13

I am trying to run npm install from the cmd in a windows environment. The following error occurs:

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Is there a reason why \node_modules\npm\bin\ repeats within the file path? I've set the environmental variables to:

C:\Program Files\nodejs\node_modules\npm\bin

and to:

C:\Program Files\nodejs\

Is there a solution to fix this issue so that I can run the npm commands?

7 Answers 7

9

Copy the directory named npm from your installed node path (In my case the npm directory was available in C:\Program Files\nodejs\node_modules).

Navigate to C:\Users\%USERNAME%\AppData\Roaming\npm\node_modules and paste the copied npm directory there.

this should work.

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

Comments

5

Run this line in terminal and It should work ;-) Good Luck !

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

1 Comment

in case of space I suggest the command SET PATH="C:\Program Files\Nodejs;"%PATH%
2

I was getting this error after installing with nvm for Windows: https://github.com/coreybutler/nvm-windows.

I just reinstalled Node in Git Bash instead of PowerShell.

Comments

1

I had the same problem. This is occurring because you have added two conflicting paths at the same time. Adding nodejs path will be sufficient as it is already bundled with npm.

What You should do ?

  1. Delete "C:\Program Files\nodejs\node_modules\npm\bin" path from your environment variables and only keep only "C:\Program Files\nodejs"
  2. Then Restart the computer
  3. Check if it is working by command ( npm --version and node --version )

I hope it is working correctly.

Comments

1

Remove Nodejs Completely and delete all the related files from program file and appdata local roaming etc then..

also uninstall nodejs software

Just remove all the paths from environment variables i.e. system and user regarding npm and node etc.

and after applying all changes just restart pc and add path in SYSTEM PATH as :

C:\Program Files\nodejs

Done :)

USER ENVIRONMENT VARIABLE OF PATH AFTER INSTALLING NODEJS AGAIN. It adds this automatically and it started working

SYSTEM ENVIRONEMNT VARIABLE OF PATH AFTER INSTALLING NODEJS AGAIN. It adds this automatically and it started working

so it add those by its own :)

Hope this helps!!

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

if you open it from vs code right click the file and open with in integrated terminal

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

The above solutions did not work for me , after trying everything , i finally delete npm-cache file located in C:\Users%USERNAME%\AppData\Local\npm-cache and it solves my issue. Try this .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.