I got path error : [module not found] whenever I try to run any npm related command in VS Code

1.2k Views Asked by At

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?

1

There are 1 best solutions below

2
Rod On

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