I've upgraded to the yarn version 3.1.0 (previously was 1.x and everything worked fine).
In the package.json of the project there is a script with the next structure:
"scripts": {
"someScript": "export NODE_ENV=development && ...",
}
When running
yarn run someScript
or
yarn someScript
shell outputs
command not found: export
When running in the shell export command itself it's found and lists found environmental variables.
What's the problem of running scripts with yarn consisting "export" command (for setting environmental variables)? What should be written and where for it to work as in version 1.x or is there a new way to set environment?
export is a shell builtin.
Try without export, something like:
"scripts": {
"someScript": "NODE_ENV=development env",
}
Related
I am trying to yarn start with git bash
"start": "node scripts/start.js",
It always works when using PowerShell or CMD.
But it does not work with git bash.
But when I tried to node scripts/start.js instead yarn start with bash it works!
I tested git bash
yarn -v, node -v, npm -v,
every command works well.
But not work with scripts...
This is the error message
'node' is not recognized as an internal or external command
And i tried to
"startStart": "yarn start",
And this time bash gives me this error message
'yarn ' is not recognized as an internal or external command
I checked my env PATH but all is fine.
--- ENV
VS_CODE
OS : window 10
node : 13.5
npm : 6.13.4
I installed git-bash with git
And all install config is default-standard
Add
I think Git-Bash can find the path when it is alone
I think we should focus on that it can't find path only when it try to trigger package.json scripts
About .profile I didn't know what it is and I never created it.
If it is not default - exist I don't have it.
without to relate to windows specific, npm executes scripts commands (specified in package.json) under the default shell, but it does not perform a login to the shell.
for instance, a bash login (bash --login) in order to use your custom system environment variable.
you can change this by using .npmrc file and set the script-shell. see this answer for the solution.
i hope this is what you suffer from :)
I'm setting up an automator run shell script to go to a specific folder on users machines and then yarn run dev but when it gets to the yarn part it can't find yarn.
-line 1: yarn: command not found
If I use terminal then yarn will run fine.
I have yarn installed -g which is in my NVM modules.
Here is my script in automator.
cd ~/Documents/myProject
yarn run dev
Also tired this setup:
Like this:
export PATH=$PATH:/Users/me/.nvm/versions/node/v10.16.3/bin
cd ~/Documents/myProject
yarn run dev
The first line tells bash where to look for programs, such as yarn and node.
When I run npm commands on my Windows 10 machine, new processes seem to spawn in new windows.
On my (Mac-using) colleagues machines, I see that these commands run in the same terminal window from which they were called. This is the behaviour I'd expect and is much more useful - it's really hard, for instance, to see my test results in the split second between them finishing and the terminal window being closed!
As an example, our packages.json has a script to run jest:
scripts": {
"test": "jest"
}
When I run npm run test, the following gets written to the current terminal:
$ npm run test
> #headuplabs/mobile#0.0.1 test C:\Users\TomWright\Documents\Repos\HeadUp.Mobile
> jest
But the actual execution of jest then gets started in a newly created window:
I'm using "git bash" as my default integrated terminal in VS Code, but I'm able to replicate this using cmd.exe and outside VS Code (i.e. by running git bash or cmd standalone).
I presume that my npm installation is improperly configured, but my Google search haven't yielded any answers.
Does anyone know what I'd need to do to make npm processes run in the same terminal window?
As mentioned in "how to set shell for npm run-scripts in windows", you might want configure the shell in npm itself:
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"
That would avoid the default setting, which can trigger a new shell window.
I have a package.json file with the following script defined:
"scripts": {
"test": "./node_modules/selenium-cucumber-js/index.js"
}
When I run npm test on linux or mac this script runs as expected. On Windows however I get an error:
/node_modules/selenium-cucumber-js/index.js
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed. See above for more details.
However if I run the command ./node_modules/selenium-cucumber-js/index.js directly from a cmd prompt it works correctly. The same issue also occurs if I try to run any other script through npm that starts with a ".". I haven't been able to find any other thread talking about this as an issue.
I am running npm versions 5.6.0 on Windows 10 Home.
Does anyone know how I can get this working?
Since npm 5.1
npm config set script-shell "C:\\Program Files (x86)\\git\\bin\\bash.exe"
or (64bit installation)
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"
Note that you need to have git for windows installed.
You can revert it by running:
npm config delete script-shell
Everything defined under scripts gets executed in the default system shell and on Windows ./node_modules/selenium-cucumber-js/index.js is definitely not a valid command (or rather a path). It just happens that the same file has a +x argument and a shebang pointing to a Node.js (or another JS interpreter) binary so that it gets executed on Linux without intervention.
I'm quite certain you'll get the same error if you were to execute the same command in the default Windows shell (cmd.exe) but you may get away with it in some ports/emulations of *nix shells (i.e. Cygwin, MSYS, bash.exe etc.) which may give you a false sense of everything working correctly outside of the npm chain.
If you want to make sure your script gets executed by Node.js while using relative paths and keeping cross-platform compatibility, call it explicitly as:
"scripts": {
"test": "node ./node_modules/selenium-cucumber-js/index.js"
}
This will also take care of things like not having a proper x flag or shebang in the script you're executing and since Node.js is perfectly comfortable with using *nix paths on Windows it won't complain either.
Whenever you write a shell script, you need to specify which shell it is written for. For inline package.json scripts, you should do this in an .npmrc alongside your package.json, like this:
script-shell = bash
If you don't specify a shell, npm is free to pick any old shell. On Windows, it picks cmd.exe, which is almost never what you want.
(Note: I don't recommend using npm config set for this. It sets local user configuration. The correct shell should be stored in version control alongside your scripts.)
I have installed spark on my Mac, following the instructions in the book: "Apache Spark in 24 Hours". When I am in the spark directory, I am able to run pyspark by using the command:
./bin/pyspark
To install spark I created the env variable:
export SPARK_HOME=/opt/spark
Added it to the PATH:
export PATH=$SPARK_HOME/bin:$PATH
The book says that I should be able to run the "pyspark" or the "spark-shell" command from any directory, but it doesn't work:
pyspark: command not found
I followed instructions on similar questions asked by others on here:
I set my JAVA_HOME env variable:
export JAVA_HOME=$(/usr/libexec/java_home)
I also ran the following commands:
export PYTHONPATH=$SPARK_HOME/python/:$PYTHONPATH
export PYTHONPATH=$SPARK_HOME/python/lib/py4j-0.9-src.zip:$PYTHONPATH
When I run the env command this is the output:
SPARK_HOME=/opt/spark
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/hq/z0wh5c357cbgp1dh33lfhjj40000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.fJdtLqZ7dN/Render
TERM_PROGRAM_VERSION=361.1
TERM_SESSION_ID=A8BD2144-72AD-402C-A591-5C8A43DD398B
USER=richardgray
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.cQeqaF2v1z/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PATH=/opt/spark/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin: /Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/heroku/bin:/Users/richardgray/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
PWD=/Users/richardgray
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
LANG=en_GB.UTF-8
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/richardgray
PYTHONPATH=/opt/spark/python/lib/py4j-0.9-src.zip:/opt/spark/python/:
LOGNAME=richardgray
_=/usr/bin/env
Is there something I am missing? Thanks in advance.
You wrote that
When I am in the spark directory, I am able to run pyspark by using
the command: ./bin/pyspark
You created export SPARK_HOME=/opt/spark
Can you please confirm that spark directory is indeed /opt/spark ?
If you execute spark from /Users/richardgray/opt/spark/bin please set:
export SPARK_HOME=/Users/richardgray/opt/spark
followed by:
export PATH=$SPARK_HOME/bin:$PATH
Note: If it solve your problem, you'll need to add those two exports to your login scripts (e.g. .profile) so the path will be set automatically