1

Whenever I try to run any npm related command such as npm -v or npm install , it gives me the error:

enter image description here

From the screenshot, you can see that it is trying to navigate to find the module but the module can not be found at:

C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js

Actually, the location of the npm-cli in my system is:

C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js

In fact, I have set the path in the environment variable like this:

User variables:

enter image description here

System variables:

enter image description here

The solution I got is to run this command every time I want to run any npm related command:

SET PATH=C:\Program Files\Nodejs;%PATH%

But it is not a solution to run this command in the terminal every time I start working on my project in VS Code. I want to permanently set the path in the environment variable.

How can I resolve this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Ibad Shaikh
  • 2,704
  • 3
  • 15
  • 27

1 Answers1

1

Same issue, this was first major post I saw, so adding my fix for others who find themselves here. Hope it's helpful:

Restart PC, open VS Code, and delete any terminal instances that are still open, as they will not inherit the new path(s) if they are 'session-restored'.

My root cause was updating Node, which for whatever reason prefaced an environmental variable in $PATH$ with a semi-colon ';'. Worked in external cmd.exe, but didn't work in VS Code integrated terminal until I realized I had to restart the old ones.

This thread was the one that eventually got me there: VS Code terminal doesn't recognize PATH variables

Rod
  • 51
  • 3
  • OMG, thank you! I was dying here. Everything was set but no single npm command was recognized. Closing terminals in IDE fixed the problem. – SharpBCD Dec 09 '22 at 12:01
  • Since posting this, I started using WSL2 with VS Code, which includes bash terminal. Highly recommend setting up WSL2! – Rod Dec 11 '22 at 04:14