I'm running npm on windows and would like to use & style parallel operations in run-scripts but running in parallel in cmd is kind of messy in my package.json file I'd like to write-
scripts: { "go": "cmd1 & cmd2"}
but npm executes the script under cmd.exe which does not know about ; I could change this to scripts: { "go": "bats/bat1.bat") where bat1.bat is a cmd bat file that uses the windows style call or start commands to run commands in parallel. which works but gives me a script that only works on windows
it would be a lot simpler if I could get npm to run the script under a bash clone or cygwin I tried config: { "shell": "bash"} but that still ran cmd.exe
is there any way to tell npm to run-scripts using a specific shell (not cmd.exe)?
just using CMD's way to run
.json .bat.bat
!Since npm 5.1
or (64bit installation)
Note that you need to have git for windows installed.
You can revert it by running:
Ideally, overriding the npm shell config parameter should work, but npm (at least version 1.4.14) seems in Windows to ignore the setting and use cmd.exe instead.
Use the following command in your bash or Git Bash shell to find out the shell setting:
By default, the output will be:
However, to override the default shell parameter, you can add (or edit) an npmrc file to the \Users\yourusername\AppData\Roaming\npm\etc directory. Just add the following line:
The path you use can be any valid path to bash.exe. Now, if you run the above "npm config ls -l | grep shell" command, you will see the following output, indicating that the shell parameter has been overriden:
One day, perhaps, a new version of npm will pay attention to the overridden shell parameter.
Just those who maybe had the same problem as me: I could run
npm start
on windows cmd, but couldn't run it on (git) bash. I got an error of:I searched the web for two days, while mainly saw ideas for adding nodejs path to the system environment variables path. What at the end fixed my problem was the line the Qwerty wrote above... Thanks Qwerty :)
Use a specifically created node_module for this purpose. I suggest using npm-run-all, but others exists, such as parallelshell.
Parallelshell example is below for drop-in-replacement for your question.
following command:
works both on windows and unix(Linux/MacOS).
Interestingly npm-run-all does not support shell commands; therefore we need to put all shell commands to separate scripts like below.
Following command:
works both on windows and unix(Linux/MacOS).
Here's one way to do it:
In your package.json file, add a line to run the script using bash. For example:
Now you can run your bash script from npm by:
Not very elegant, but it works.
If you are developing in both Windows and Linux/Unix, then at least this approach is fairly portable to both environments.