Npm install cannot find module 'semver'

I cannot use npm install using the command line in NodeJS. I get 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.<anonymous> (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

+170
javascript mean-stack
Nov 23 '15 at 11:55
source share
21 answers

I had the same error. npm uninstall npm -g , rm -rf node_modules did not help me, because when I tried, I received an Error: Cannot find module 'semver' message Error: Cannot find module 'semver' . But I solve my problem with these steps (this will remove the other global modules that you can use):

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

Hope this helps those who get a similar issue.

+361
Feb 24 '16 at 8:35
source share

I am facing the same problem here.

If this happens immediately after running brew install yarn try running yarn global add npm and voila - fixed!

+63
Mar 22 '18 at 6:42
source share

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

+48
Dec 06 '16 at 17:02
source share

I also had this, after yesterday's brew install yarn . At least before that, everything was fine.

I ran rm -rf node_modules and tried to reinstall, but the npm command did not work.

In the end, I took a fairly simple step to reinstall Node through the official Node installer for Mac OS X.

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

Now everything is all right. Just went back to the directory, launched npm install , and it did the trick.

+45
Mar 20 '17 at 10:43 on
source share

In Arch Linux , what was the trick for me:

 sudo pacman -Rs npm sudo pacman -S npm 
+18
Sep 30 '17 at 3:27
source share

Just running into this in Arch Linux 4.13.3, I solved the problem by simply reinstalling semver :

 pacman -S semver 
+13
Sep 29 '17 at 15:41
source share

In fact, this is a link to previously saved modules.

Solution: Delete the npm-cache / npm folder in the nodejs installation directory. On Windows, this is in C: / User / Username / Appdata / Roaming / npm (or npm_cache). and try installing again.

Do the same in any OS.

+6
01 Oct '17 at 16:20
source share

Node MSI booted up again on Windows, and doing a repair worked for me.

+4
Jun 14 '17 at 20:59 on
source share

Faced this problem when I launched npm install using a lower version of the node. Later, when I upgraded to the latest version of the node and started gulp , it showed this error.

To fix it, I deleted node_modules and restarted npm install . Then gulp ran fine.

+2
Feb 26 '18 at 12:04 on
source share

Just delete the / node_modules folder and try again.;)

You can use npm rm to remove it.

You can also check this issue on GitHub. To be more specific about volatility, try following this :

Delete

It’s so sad to see you leave.

sudo npm uninstall npm -g Or, if that fails,

sudo make uninstall More serious uninstallation

Usually the above instructions are sufficient. This will remove npm, but leave everything you installed.

If you want to remove all the packages you have installed, you can use the npm ls command to find them, and then npm rm to remove them.

To remove the cruft left behind npm 0.x, you can use the included clean-old.sh script file. You can run it like this:

npm learn npm -g-sh scripts / clean -old.sh npm uses two configuration files, one for configurations for each user and one for global (each user). You can view them by following these steps:

npm config get userconfig # defaults to ~ / .npmrc npm config get globalconfig # defaults for / usr / local / etc / npmrc Removing npm does not delete the default configuration files. You must delete them yourself if you want them to leave. Note that this means that future npm installations will not remember the settings you have selected.

+1
Nov 23 '15 at 12:08
source share

I had the same problem, but it was caused by a broken package-lock.json file.

Removing package-lock.json and running npm install again fixed it for me.

+1
Jul 14 '17 at 4:37
source share

I finally figured it out! Yes, you need to delete / delete all files and reinstall. BUT SOME OF THE FILE WAYS SHOULD REMOVE DURING THE DESTRUCTION PROCESS. File paths are so long in Node that they cannot be deleted. You must rename the file paths.

After removing Node, use Command Prompt, go to ... \ Appdata \ roaming \ (use the path from the error message). Try deleting the folder with del npm. Then, if it does not allow you to delete the folder, start renaming the folders in the file path in the next error message "a" or something short. You may need to do this for several folders along the way. Then you can delete! Then reinstall Node and it should work.

+1
Nov 09 '17 at 15:12
source share

In my case, just restarting brew install yarn fixed the problem.

0
25 Oct '17 at 22:31 on
source share

I encountered the same problems after brew installed yarn on my MacOs Sierra 10.12.6. (And the first installation attempt will fail after brew to update itself with the message β€œHomebrew should be running under Ruby 2.3! You are using 2.0.0 (RuntimeError).” So I restart it.)

Therefore, I use n manager to reinstall npm.

  • switch to another version of node (for my case up to 8.0) using the "n" command with empty parameters
  • or install a new one using "n xxx", where xxx is the version number of the node (I need 6.9.1)
  • delete the working version using "n rm xxx", where xxx is the version number of the node. use sudo if necessary
  • set the working version to "n xxx", where xxx is the version number of the node. use sudo if necessary
  • switch to the working version of node. (see first step for reference)

I think the problem may be caused by the fact that node was installed in sudo for the case.

0
Nov 02 '17 at 10:04 on
source share

For Mac users, I tried installing a bunch of new node versions and uninstalling different ones. This did not fix it. You must completely erase all your settings first. Follow these instructions ... How to completely remove Node.js and reinstall it from the very beginning (Mac OS X) .

Then download the latest version of the site.

0
Jan 23 '19 at 17:31
source share

I had the same problem when installing on AWS Linux. I had to install it using sudo . Therefore, to get around this, I followed step 3 of this article (to get the latest version of the site)

https://www.hostingadvice.com/how-to/update-node-js-latest-version/

 wget https://nodejs.org/dist/vx.xx/node-vx.xx-linux-x64.tar.xz tar -C /home/aUser/node --strip-components 1 -xJf node-vx.xx-linux.x64.tar.xz 

But installed it in the user's home directory /home/aUser/node . Then added this path to my path.

export PATH=/home/aUser/node/bin:$PATH

After that, I was able to npm install without problems.

0
Jan 27 '19 at 19:02
source share

I ran into these problems when starting a project on a higher version of cli. To solve this problem, you can just comment out the @ angular-devkit / build-angular module and again you need to reinstall it through

npm install @ angular-devkit / build-angular --save

0
Mar 19 '19 at 6:24
source share

Just make sure semver installed: npm install -g semver

0
Apr 10 '19 at 13:40
source share

In my case on macOS (10.13.6), when I ran the following command

 npm install -g react-native-cli 

I got this error

 Error: Cannot find module 'semver' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:2:14) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) 

The error was resolved after the command

 yarn global add npm 

suggested by @Ashoor

0
Aug 19 '19 at 17:45
source share

Just check your preinstall scripts if you have them. Sometimes, in order to limit the versions of node and npm you need to run a project.

In this case, you need to install semver manually via npm install -g semver

-one
Aug 02 '18 at 8:16
source share

I ran into the same issue and fixed it by updating the version of Node

-3
Jun 29 '18 at 18:40
source share



All Articles