Robert
Robert

Reputation: 333

Why does VsCode NPM throw a module not found error?

Typically I have no issues at all but however the other day VsCode started throwing a error anytime I tried to use a nodejs command. For instance even NPM -V throws a error. I have attempted to delete the environmental variables and reapply them as well as restart and I even completely wiped nodejs from my system both under program files and appData and re installed it. If I goto a normal cmd windows prompt I get zero issues. However if I am inside of vscode I get the below error:

 npm -v
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'E:\c\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'E:\c\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3) 

This is just a simple version command in VScode. Thanks in advance for the help!

Upvotes: 0

Views: 12769

Answers (2)

SeaMouse
SeaMouse

Reputation: 31

If selecting the simple CMD as the default terminal in VsCode does not fix this problem for some, try running VsCode as an administrator.

Upvotes: 0

Robert
Robert

Reputation: 333

I was able to resolve this by pressing F1 in VsCode and selecting the cmd as the default terminal option. The guys at vscode actually helped me! https://github.com/Microsoft/vscode/issues/65893

Thanks! Hopefully this helps someone in the future :)

Upvotes: 3

Related Questions