12

I have a package.json file that looks like:

{
  "name": "APP",
  "version": "3.0.0",
  "private": true,
  "scripts": {
    "start": "node app.js",
    "test": "./test/dbLoad && env db=test test=1 jasmine"
  }
}

When I run npm test, I get an error:

'.' is not recognized as an internal or external command

I'm guessing this is because node is using windows cmd.exe. The command works fine if i preface it with bash. Can I change a configuration setting of some kind in node so that it automatically uses bash?

2 Answers 2

11

Set NPM's script-shell to point to Git Bash (note the newer path):

npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"

This tells NPM to run scripts defined in your package.json (such as start or test) using the specified shell instead of the default, which on Windows is cmd.exe. See https://docs.npmjs.com/misc/config#script-shell.

Sign up to request clarification or add additional context in comments.

Comments

6

Yes you can!

Before running npm run you should do:

set comspec=your_bash.exe_folder

The NPM package, check the comspec enviroment, and run it on win32. By default ComSpec=C:\windows\system32\cmd.exe

For more info you can see the source code of NPM: lifecycle.js (Line 219)

if (process.platform === 'win32') {
    sh = process.env.comspec || 'cmd'
    shFlag = '/d /s /c'
    conf.windowsVerbatimArguments = true
  }

You can set the environment comspec, to your bash by default by using the registry. If you need any help, please comment.

4 Comments

Will this change the shell for my entire system or just for when i run node?
tried typing set comspec='C:\Program Files\Git\bin\bash.exe' and it didnt stick. Also tried setting the ComSpec variable via control panel, and running npm test still fails with the same error.
I tried on my machine, and it's working. Did you type set compspec=... without the quotes? Did you see that the comspec updated? (using set com)
I had the same problem @RobbyAllsopp. I fixed using export "comspec=C:\Program Files\Git\git-bash.exe"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.