29

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?

Alex
  • 371
  • 1
  • 3
  • 5

11 Answers11

46

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

12

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
Aiden Ray
  • 369
  • 4
  • 14
8

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.

Alex
  • 371
  • 1
  • 3
  • 5
3

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

CSLf
  • 31
  • 2
1

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
Community
  • 1
  • 1
royki
  • 1,593
  • 3
  • 25
  • 45
  • I have node in my path variables. I have the same path variables as my other computer (which npm works fine on btw) Here is an image for npm not working but node working https://drive.google.com/open?id=0B_NN3_r3g9pyMV8tVkpmdzZLNmM here is my path variables with nodejs in it https://drive.google.com/open?id=0B_NN3_r3g9pyNjY3TWpQWXNuY1E – Alex Aug 29 '16 at 07:28
  • Ok I updated the answer. Check those link. Did you try to run from cmd? Does it work from cmd ? – royki Aug 29 '16 at 17:13
0

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

Berty
  • 1,081
  • 1
  • 18
  • 49
0

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.

DixiPoowa
  • 133
  • 12
0

I solved it like this: You probably have an old installation that has not been completely deleted. Remove NODE and NPM again by following this link: How to completely remove node.js from Windows. And then install again.

ben
  • 71
  • 1
  • 4
0

For my case, and it's working fine for me:

  • I have delete folder npm folder in path: C:\Users\ [YOUR USER]\AppData\Roaming\npm

  • I have delete folder npm-cache folder in path: C:\Users\ [YOUR USER]\AppData\Roaming\npm-cache

0

This problem arose for me when I installed a new terminal from the Microsoft webstore. When installing that I think I gave it many permissions that I wasn't completely sure of! I mean I was doing what it wanted me to do.

But this action of mine caused the error for me whenever I was starting or running a node server.

The system cannot find the path specified.

I tried many solutions including reinstalling the node, checking the path in the environment variable, etc. But the thing that worked for me was:

npm config set script-shell powershell

This script configured powershell as a terminal to be used for npm commands.

-1

if you are using windows you might need to do this :

"scripts": {
    "server": "cd .\\server && npm run start",
    "client": "cd .\\client && npm run start",
    "dev": "concurrently \"npm run server\"  \"npm run client\""
  }

You need to go to the correct folder path by using .\\.