double dot-slash not recognized in command prompt - running npm command

Viewed 170

I have the following in my lerna project package.json:

{
  "scripts": {
    "build": "../../node_modules/.bin/tsc"
  }
}

When running this on a Windows bash.exe, I get

'..' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-package@1.0.0 build: `../../node_modules/.bin/tsc`

I tried: "build": "\"../../node_modules/.bin/tsc\"" with no luck. I want this command to work on both Windows and Mac. How do I achieve this?

1 Answers

I use Git Bash on Windows and the issue cropped up one day when I ran one of my npm scripts. By default on Windows, npm runs scripts using cmd.exe and which doesn't understand dot-slash notation.

The solution for me was to set npm to run scripts in bash.

For 64-bit:

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

For 32-bit:

npm config set script-shell "C:\\Program Files (x86)\\git\\bin\\bash.exe"  

Alternatively, I believe the git for windows installer lets you add unix capabilities to command prompt, but I didn't test this as the npm config set command worked for my needs.

Related