17
votes

I have installed nodejs. When I try and use npm via power shell or cmd it returns

The system cannot find the path specified.

If I run node -v everything works fine. I can use npm via the nodejs console just fine as well. I've tried uninstalling and reinstalling nodejs multiple times and it didn't help.

Any ideas on what is causing this?

7
Do you have the path to nodeJS in your path? - Chris Neve

7 Answers

27
votes

For anyone who runs into this trying to debug this error on why npm run <script> doesn't work on Windows for things in node_modules/.bin/ such as gulp, it relates to the fact that npm is using cmd.exe instead of bash for the child.

You can fix this with NPM 5.1.0+ using npm config set script-shell bash

10
votes

I had exactly the same issue and solved it by following the steps in npm Troubleshooting as linked by @royki

  1. install the latest globally npm install -g npm@latest
  2. I applied Options 1. and 2. consecutively in the npm Troubleshooting Upgrading on Windows
  • Option 1: edit your Windows installation's PATH to put %appdata%\npm before %ProgramFiles%\nodejs. Remember that you'll need to restart cmd.exe (and potentially restart Windows) when you make changes to PATH or how npm is installed.

  • Option 2: remove both of

    • %ProgramFiles%\nodejs\npm
    • %ProgramFiles%\nodejs\npm.cmd
6
votes

I found the problem. I needed to move my node paths further up the list. Windows must have been looking for NPM in the wrong path variable. I moved my node path to the top of the system path variables and now NPM works.

Thanks for the help.

1
votes

For me, nothing else worked. The problem was solved by invoking npm install after deleting node_modules folder.

0
votes

Assuming you installed Node in Windows. Normally NODE_PATH should be automatically added.

For your case check the below SO Post

Check also this post for ENVIRONMENT SET UP of NODE for Linux and Windows OS.

Updated

  1. Troubleshooting npm
  2. npm-windows-upgrade
0
votes

For me it was a script that i set to autorun in the windows registry and i had moved the script without changing the path in the registry.

Deleting this key fixed my issue:

Computer\HKEY_USERS\S-1-5-21-1659004503-1897051121-1177238915-282167\Software\Microsoft\Command Processor\AutoRun

https://stackoverflow.com/a/59584302/373207

0
votes

For me, I simply had a folder name with a space in the path and that was treated as a new command.

For context, my npm start does this

"setup-dev-test-env": "cross-env __fakedirname=%cd% PUBLIC_URL=id-000/fake/path/to/index.html NODE_ENV=development REACT_APP_MOCK_HOSTNAME=localhost REACT_APP_MOCK_PORT=69 REACT_APP_ROOT_QUERY_PARAM=/ro/420/ot.ini",
"start": "npm run setup-dev-test-env react-scripts start"

and, since the current folder path (%cd%) included a space, it would try and run something that didn't exist.