2
$ npm install
module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

I have noticed this

C:\c\Program Files\

I think that the path is being overrided, I have set the paths in my environment variables

NodeJs works good when I donode -V I get the version and when I do npm -V it crashes how can I solve this

PS: I am using Windows 10 Pro

3
  • What's your PATH set to? (echo $PATH) Commented Aug 10, 2017 at 9:52
  • Not sure what this has to do with either git or bash, can you check if npm crashes with the same error if you run it from the command prompt that comes with Windows? Commented Aug 10, 2017 at 10:22
  • Yes I have tested it in power shell and it works just fine, but I need to fix and git bash too for some reasons Commented Aug 10, 2017 at 10:39

4 Answers 4

4

In Program Files\nodejs\npm, node.exe is executed and not a node script, because of this, git-bash converts npm-cli.js's path to a Windows path.

npm Version: 3.10.10
Platform: MINGW64_NT-6.1 2.5.0(0.295/5/3) 2016-03-31 18:47 x86_64 Msys

When I run npm (/c/Program Files/nodejs/npm) in a git bash (which uses MINGW) the npm script throws: Error: Cannot find module 'C:\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'

The problem is that the npm shell script executes a window node.exe but supplies it with a unix path for the npm-cli.js.

As I see it the fix is to also convert the path with cygpath for MINGW as well in /c/Program Files/nodejs/npm line 6-8:

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
    *MINGW*) basedir=`cygpath -w "$basedir"`;;
esac

Read NPM issue #18499 on GitHub for more information.

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

Comments

2

I have found a solution, it's due to this variable located in environment variables:

MSYS_NO_PATHCONV=1

I don't know why this conflict is happening, in any case If i find it I will update my answer

Comments

0

you should install the only LTS version of node https://nodejs.org/en/

1 Comment

It's the LTS version that has this problem!
0

If you have reinstall the Node.Js and previously you have set the node path in environment variable then you should remove it then it will work

Comments

Your Answer

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