Cannot find NPM - node.js

If I run where npm I get:
C:\Users\ralbritton\AppData\Roaming\npm\npm
C:\Users\ralbritton\AppData\Roaming\npm\npm.cmd
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
C:\Program Files\Git\usr\local\npm
C:\Program Files\Git\usr\local\npm.cmd
But when I try executing anything with the NPM command I get:
internal/modules/cjs/loader.js:985
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
For reference, I I run
where node returns C:\Program Files\nodejs\node.exe and node -v returns 12.16.1
IT appears that its searching for npm in the wrong directory. How do I change where its looking since I can not access any of the confis through npm commands?
UPDATE: I just happened to open up my command window and was able to run commands just fine. I was using the GIT bash window previously so maybe the problem is with GIT bash?

Related

How can I resolve cannot find module npm-cli.js error?

My npm has worked well, however today it shows an error saying,
Error: Cannot find module 'C:\Users\mrsim\node_modules\npm\bin\npm-cli.js'
My npm worked well just an hour ago. I typed "npm start" inside of VSCode to start my react-app and it worked very well!
This nightmare started when I created server folder and typed "npm install express".
Normally when I typed "npm install express" in the terminal, it automatically created node-modules folder and package.json for me without any problem, but none of these appear.
To solve this problem I repair node first, and didn't worked.
Next I changed my environment variable, and didn't worked.
Next I used
"SET PATH=C:\Program Files\Nodejs;%PATH%" this sentence in the terminal, and didn't worked.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Users\mrsim\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Users\mrsim\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
This is error message appear on terminal. If i go to that directory, i cannot find npm.cli.js
What should I do...?
Okay, it seems like you installed the npm module in a wrong directory. To fix, this follow the following steps,
Open File Explorer and go in this directory,
C:\Users\mrsim\
You will see a folder named "node_modules". Delete it completely.
Now open up your command prompt
Copy your project directory and paste the following:-
cd <project_dir>
Run,
npm install express
Now it should be installed in the correct directory!
Go to the path that have Appdata\local or Appdata\roaming
Delete the npm and npm cache folder in both
Get back in terminal, Run npm install again, will see a new path ex: npm notice
Run npm install -g npm#8.15.0 to update!
Install the new path and ready to go
This solved my problems.

How to install back the npm module in Node.js

Today, I wanted to download a module via NPM.
Thought, because Node.js can't find the NPM modules that I install, maybe, I need to run NPM via the admin PowerShell, in the folder C:\Program Files\nodejs\node_modules. So, did it, ran the command:
npm i node-red-contrib-mihome
Somehow, it worked, but then, any other NPM installation did not start. That was because of this error:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v17.2.0
Now, I don't have the npm module inside the node_modules folder.
How to get it back?
Thank you, #Anis, for the answer.
Run the Node.js installer (if you haven't deleted it)
Click Next, then Repair.
Then, click Repair again and wait
Click Finish
Now you should have the C:\Program Files\nodejs\node_modules\npm module.
way1:
Download node (zip format) from the node.js official website, extract it and copy it to the node file. Enter npm update at the terminal.
way2:
Set environment variables
SET PATH=C:\Program Files\Nodejs;%PATH%

Npm can no longer be found in node_modules folder

I installed nvm for windows (https://github.com/coreybutler/nvm-windows) and switched to an older node version (v8.17.0). Since doing this, npm no longer works and returns:
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
module.js:550
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
I checked, and indeed although the folder C:\Program Files\nodejs\node_modules\ exists, it is completely empty. So npm indeed doesn't exist in that folder. where npmreturns:
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
C:\Users\MyName\AppData\Roaming\npm\npm
C:\Users\MyName\AppData\Roaming\npm\npm.cmd
Here I read to run SET PATH=C:\Program Files\Nodejs;%PATH%, which I did, but that made no difference (still the same error when running npm).
I've also tried re-installing npm using the steps here, but after re-installing it, it still gives the above error.
How can I solve this?

npm not running after Node upgrade

I upgraded Node from version 10.17 to 12.6.1 on my Windows 10 Pro x64 machine and npm does not run. The error i get is:
internal/modules/cjs/loader.js:985 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:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }
internal/modules/cjs/loader.js:985 throw err; ^
I have tried so far:
All the answers and solutions on this question and the
issue still persists.
Uninstalling Node, deleting all npm, node_modules and node folders
on Program Files and AppData, rebooting, installing node again,
rebooting and it still did not work.
Reinstalling npm as per the instructions here
My system Path variable contains C:\Program Files\nodejs\ and my user Path variable contains C:\Program Files\nodejs\;C:\Users\{User}\AppData\Roaming\npm
What am I missing here? Can anyone guide me?
I moved the folder of node to the folder of the project end update the path end it finally solved the problem no idea why

npm install and ng serve command not working despite having npm and proper path set up

I have all the required packages to run node and angular app. Everything was working fine and out of nowhere all hell broke loose. Now, when I try to run npm install to install all the dependencies of the project, I get the following issue:
$ npm install
module.js:540
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
and when I try to create a new angular app, I get the following error:
ng new angular-app
module.js:540
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\node_modules\#angular\cli\bin\ng'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
Here's my PATH env variable:
C:\ProgramData\Oracle\Java\javapath;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\VG\Utils;
C:\Program Files (x86)\Lotus\Notes;
c:\oracle32\ora121\bin;
C:\Oracle64\ora121\bin;
C:\PROGRA~2\IBM\SQLLIB\BIN;
C:\PROGRA~2\IBM\SQLLIB\FUNCTION;
C:\PROGRA~2\IBM\SQLLIB\SAMPLES\REPL;
C:\PROGRA~2\ibm\gsk8\lib;
C:\Program Files\IBM\WebSphere MQ\Java\lib;
C:\Program Files (x86)\apache-maven-3.2.5\bin;
C:\Program Files (x86)\Java\jdk1.8.0\bin;
C:\Program Files\nodejs\;
C:\Program Files\Microsoft VS Code\bin;
C:\Program Files\Git\cmd;
C:\Users\UNBP\AppData\Local\Microsoft\WindowsApps;
C:\Users\UNBP\AppData\Roaming\npm
PATHEXT=.COM;
.EXE;
.BAT;
.CMD;
.VBS;
.VBE;
.JS;
.JSE;
.WSF;
.WSH;
.MSC
I have gone through all the posts here npm-cli.js not found when running npm, but that didn't solve my issue.

Resources