I can\'t use npm install
using the command prompt in NodeJS. I\'m getting these errors when running npm install
:
module.js:339
Faced this issue when I ran npm install
using a lower version of node. Then later when I upgraded to latest version of node and ran gulp
, it has shown this error.
To resolve, deleted node_modules and re-ran npm install
. Then gulp
ran fine.
In my case on macOS(10.13.6), when I executed 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 got resolved after executing the command
yarn global add npm
proposed by @Ashoor
In my case, on macOS, I fixed this by installing the latest Node and npm versions from https://nodejs.org/en/download/
Just make sure semver
is installed: npm install -g semver
if you are in Linux server exit from the server and re ssh
On Ubuntu, if you would rather manage Node through the default repositories using apt
, it's best to install both nodejs
and npm
this way.
It's very likely that the version of npm you are using is expecting semver
in a specific place that is not aligned with the version of Node JS you have installed. If there is only one version of nodejs
and only one version of npm
, and they are both installed using the default repositories, this should work perfectly.
Here is my best guidance for getting Node and npm working using the main Ubuntu repositories:
sudo apt-get purge nodejs --auto-remove
and sudo apt-get purge npm --auto-remove
whereis node
: remove all the versions of node, one at a time. Repeat until this command returns a blank after node:
.sudo apt-get install nodejs
node --version
: should return ... no such file or directory
nodejs --version
: should return v1x.x.x
. This is the version installed by apt
. It will probably be less recent that the latest version available on the Node JS website.sudo apt-get install npm
npm --version
: it will use the nodejs
installed by apt
and work correctly.