node.js npm error message - system cannot find the path specified

前端 未结 6 657
执笔经年
执笔经年 2021-01-18 00:47

I have a strange error message I don\'t understand or can\'t get rid of. Secondly when I try to create express app on webstorm it can\'t find express. I\'m using windows 7 6

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 01:17

    Had the same problem. Running npm gave me this error:

    C:\Users\user>npm
    The system cannot find the path specified.
    

    I ended up uninstalling nodejs from the Control Panel and re-installing with a fresh download.

    The error doesn't say it couldn't find the command, so I figured it was something wrong with the npm script. The script is located at C:\Program Files\nodejs\npm.cmd, found via the path var. echo %path%.

    The script contained:

    @IF EXIST "%~dp0\/bin/sh.exe" (
      "%~dp0\/bin/sh.exe"  "%~dp0\node_modules\npm\bin\npm-cli.js" %*
    ) ELSE (
      /bin/sh  "%~dp0\node_modules\npm\bin\npm-cli.js" %*
    )
    

    This looked wrong, as there are forward slashes for Windows and no sh.exe file where the script wants it to be. There is also no /bin/sh file, because its Windows :( Which is why it can't find the specified path.

    I tried to get node working in cygwin because its resembles linux and makes Windows at least somewhat bearable. Maybe this was the problem?

    Anyway after re-installing the npm.cmd file looks like:

    :: Created by npm, please don't edit manually.
    @IF EXIST "%~dp0\node.exe" (
      "%~dp0\node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
    ) ELSE (
      node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
    )
    

    The slashes look right and it works.

提交回复
热议问题