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

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.

Related

node:internal/modules/cjs/loader:1056 throw err;

I am using Node.js v19.4.0.
When I run npx create-react-app MyApp to create react project
in visual studio code editor I get the following error:
node:internal/modules/cjs/loader:1056
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
at Module._load (node:internal/modules/cjs/loader:898:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v19.4.0
node:internal/modules/cjs/loader:1056
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npx-cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
at Module._load (node:internal/modules/cjs/loader:898:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
the first solution is to uninstall the node.js and npm and then reinstall them.
or it might be because of an incorrect node_modules path. please check the path and make sure it is correct.
Downgrade to a lts supported version!
brew install node#18
brew link --overwrite node#18
node --version
worked for me. (Macbook M1; Ventura 13.1.)
First, try to clear npm cache:
npm cache clear --force or npm cache clean --force
then remove all node_modules from the application
remove the package-lock.json file from the application
Install packages again by using this command npm install
then start application using npm start
If the above solution will not work then, try to remove node.js and then re-install.
Hope this helps!

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%

Error: Cannot find module '../../package.json'

So, I've seen other similar issues. There are a lot, but I can't seem to find a solution for this.
I've already deleted node_modules folder and package-lock.json file from /{username} , where my package.json file is. However, every time I install something globally, it does not update the package.json file, but does install it in /usr/local/lib/node_modules.
This happens every time I run ncu.
Any ideas?
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '../../package.json'
Require stack:
- /usr/local/lib/node_modules/npm-check-updates/build/src/bin/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 Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js:11:40)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/npm-check-updates/build/src/bin/cli.js'
]
}
Node.js v17.0.1
I have just experienced the same. I think it's a bug in the latest version of NCU (12.0.1, released 5 hours ago at the time of writing).
If I run
npm install npm-check-updates#12.0.0 -g
then ncu runs fine.
If I run
npm install npm-check-updates#12.0.1 -g
then it barfs with this error.
I just checked the Github page and found that the issue has already been raised as https://github.com/raineorshine/npm-check-updates/issues/990.
So I guess, follow that issue for any other workarounds and the eventual fix.
I solved this to removing the node_modules folder, package-lock.json file and executing:
npm install
I've been scratching my head over this for an hour and the answer by #Alberto Manuel helped me find the solution. I, too, cleared the node_modules, package-lock.json and tried npm install but that didn't work.
Then I did npm install --legacy-peer-deps after clearing both the node_modules, package-lock.json. That finally fixed my issue.
Looks like npm install was overriding the legacy versions of dependencies with higher versions or skipping them altogether.

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 module.js:472

When I try to start any npm command, the terminal displays
module.js:472
throw err;
^
Error: Cannot find module '/usr/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:425:7)
at startup (bootstrap_node.js:146:9)
at bootstrap_node.js:540:3
I tried to reinstall node.js and npm.
How and where can I change the directory "usr/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js" to "usr/bin/node_modules/npm/bin/npm-cli.js".
p.s. When I copy all node_modules and past to /node_modules/npm/bin/, it works, but this is not an acceptable solution.
In you project folder there is a file named webpack.local.settings.js.sample. Rename the file to webpack.local.settings.js It worked for me.

Resources