How to set shell for npm run-scripts in Windows How to set shell for npm run-scripts in Windows windows windows

How to set shell for npm run-scripts in Windows


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


Here's one way to do it:

  1. Create a script, such as my_script.sh, in your project bin directory.
  2. In your package.json file, add a line to run the script using bash. For example:

    "scripts": {  "boogie": "bash bin/my_script.sh"}

Now you can run your bash script from npm by:

    npm run-script boogie

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.


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:

$ npm config ls -l | grep shell

By default, the output will be:

shell = "C:\\WINDOWS\\system32\\cmd.exe"

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:

shell = "C:\\Program Files (x86)\\git\\bin\\bash.exe"

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:

shell = "C:\\Program Files (x86)\\git\\bin\\bash.exe"; shell = "C:\\WINDOWS\\system32\\cmd.exe" (overridden)

One day, perhaps, a new version of npm will pay attention to the overridden shell parameter.