Npm install cannot find module ‘semver’

Npm install cannot find module ‘semver’

I can’t use npm install using the command prompt in NodeJS. I’m getting these errors when running npm install:
module.js:339
throw err;
^
Error: Cannot find module ‘semver’
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object. (C:\Users\admin\AppData\Roaming\npm\node_modules\npm\l
ib\config\defaults.js:6:14)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)

Please help me

Solutions/Answers:

Solution 1:

I had the same error. npm uninstall npm -g, rm -rf node_modules didn’t help me, because when I tried I was getting Error: Cannot find module 'semver'. But I solve my problem with these steps (this will delete other global modules you may be using):

  • sudo rm -rf /usr/local/lib/node_modules
  • sudo rm -rf ~/.npm
  • brew uninstall --force node
  • brew install node

Hope this will help those who are getting a similar problem.

Solution 2:

I’m facing the same issue here.

If this occurs right after you run brew install yarn try running yarn global add npm and voilà – fixed!

Related:  How to detect chrome and safari browser (webkit)

Solution 3:

On MS Windows, the solution is to remove %APPDATA%\npm and reinstall node

Solution 4:

I had this too, after running brew install yarn yesterday. At least, everything was fine up until then.

I ran rm -rf node_modules and tried to reinstall, but no npm command was working.

In the end I took the rather simple step of reinstalling Node via the official Node installer for Mac OS X.

https://nodejs.org/en/download/

Everything is fine now. Just went back to the directory, ran npm install and it’s done the trick.

Solution 5:

On Arch Linux what did the trick for me was:

sudo pacman -Rs npm
sudo pacman -S npm

Solution 6:

Having just encountered this on Arch Linux 4.13.3, I solved the issue by simply reinstalling semver:

pacman -S semver