329

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.<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)
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
user2447562
  • 3,431
  • 2
  • 16
  • 15

41 Answers41

454

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.

WoodenKitty
  • 6,521
  • 8
  • 53
  • 73
artiebits
  • 5,075
  • 1
  • 13
  • 15
  • 3
    Used this on two different machines running El Capitan, worked in both cases. – Kamikaze Rusher Mar 10 '16 at 19:41
  • 7
    Use `brew uninstall --force node` to remove all versions – deleze Jan 19 '17 at 21:53
  • I didn't use `brew uninstall --force node` at first try, it's going to break node and npm. Looks like if you have multiple version node installed, really need `--force` – Rob Lao Feb 21 '17 at 11:34
  • 8
    just install npm again. `curl -0 -L https://npmjs.org/install.sh | sudo sh` after remove npm folder – Baryon Lee Mar 14 '17 at 08:41
  • 1
    This also fixed my issue on Mac OS Sierra – WBuck Mar 22 '17 at 23:42
  • I've tried this solution, but it didn't fixed in my case. I've fixed with solution shown [here](http://stackoverflow.com/questions/30043872/docker-compose-node-modules-not-present-in-a-volume-after-npm-install-succeeds) – Hudson Santos Mar 31 '17 at 18:26
  • worst part is taht every time I want to update node I have to go through this process of completely removing node, and then adding it back. It's getting silly – Electric Coffee Apr 03 '17 at 07:33
  • This worked for me after upgrading to Node v8.0.0/npm v5.0.x – Daniel Schaffer Jun 05 '17 at 15:50
  • 22
    If Yarn is already installed, `brew uninstall --ignore-dependencies node` works for me where `brew uninstall --force node` didn't. – Maxime Lafarie Jun 21 '17 at 13:02
  • 1
    `brew uninstall --ignore-dependencies --force node` on Sierra 10.12.5 works for me – MFrazier Jul 06 '17 at 17:44
  • This worked for me. Thank you! Does anyone know why this error arose in the first place? Something about the node / npm version? One day I woke up and couldn't `npm run serve` as I had been routinely ... I'm not aware of anything at all that might have caused this change. Anyway, glad to be up and npm running again. – Leo Folsom Jul 25 '17 at 15:58
  • 24
    Its my fault for blindly pasting commands, but `sudo rm -rf /usr/local/lib/node_modules` caused me to lose global modules I use such as gulp and selenium server. **Be weary of this** – AmmarCSE Aug 18 '17 at 11:43
  • Yep - just keep in mind this deletes all global modules, such as Ionic or Gulp. Will have to reinstall them with `npm i (module) -g` – Grant Oct 30 '17 at 06:48
  • Works great! I recommend to use nvm instead of brew. – glemiere Jun 18 '18 at 16:07
  • 1
    I didn't have to delete all my global modules. Following the instructions above, I replaced this "sudo rm -rf /usr/local/lib/node_modules" with this "sudo rm -rf /usr/local/lib/node_modules/node". Basically I just added "/node" and it magically worked for me. Again, you have to still follow the instructions above :) Btw, thanks @artiebits for the solution! :) – balfonso Sep 14 '18 at 13:40
  • 1
    Save yourself 10 minutes - try this answer first: https://stackoverflow.com/a/49422151/524537 – Bojan Radivojevic Oct 31 '18 at 17:18
  • Win10: removing app's node_modules and package-lock.json, then npm install - solved issue for me. – PokatilovArt Aug 11 '20 at 23:17
  • 1
    @BojanRadivojevicBomber I with I saw your comment earlier, the above solution didn't work or at least was stuck at "make install" and now I 'have to reinstall every single package :( – Zeyad Shaban Nov 29 '20 at 06:43
  • I just had a similar issue, but with the ui5 command installed through npm. I think i had some versioning issues, but clearing the entire npm seems to have fixed it. Thanks! (for reference, I was trying to use the @ui5/cli package) – Catalin Pirvu Apr 23 '21 at 10:47
  • Someone please explain why it worked , for me also it worked – Arun Nov 18 '22 at 17:14
  • `curl -0 -L https://npmjs.org/install.sh | sudo sh` was needed. Also incase you need some specific version of node done forget to mention it like this `brew install node@16.4.2` – sibillalazzerini Apr 29 '23 at 10:56
236

if you are in Linux server exit from the server and re ssh

Supun Madushanka
  • 2,738
  • 1
  • 11
  • 11
  • 13
    This also works if you are on a local terminal session (tested on Ubuntu 20)! One year later, npm still has this issue... – Jerfov2 Aug 17 '21 at 22:15
  • 3
    Had this issue after using n to change the node version (in WSL), this answer should be higher rated ;) – Tofandel Sep 20 '21 at 11:43
  • 3
    Also worked for me on ubuntu on wsl2 – RichardAtHome Feb 18 '22 at 07:37
  • 1
    This worked like a charm, but the answer would be more useful if it explained why this worked. – tschwab Sep 24 '22 at 16:26
  • Always try the simpler answer first. Reinit VSCode and terminal fixed it for me. Using Ubuntu. – Marquez Jan 28 '23 at 23:31
  • Yup, Debian local machine, had just installed and upgraded npm. Closing the terminal and open new one refreshed something, and (npm install) it just worked. Without uninstalling/re-installing anything. Great. – Luís Osório May 13 '23 at 22:24
  • worked on orangepi 5 running armbian. I had the thread error after following this answer: https://stackoverflow.com/a/19584407 for upgrading my nodejs to the latest stable version – Gio Venice May 30 '23 at 20:21
  • Worked for me running Ec2 Ubuntu Jammy 22.04 – Metcalfe Jun 20 '23 at 21:52
  • From all the answers and re-installations I've done, I can't believe this actually worked! Thanks a lot! – jfajunior Jul 26 '23 at 12:42
108

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!

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Ashoor
  • 1,358
  • 1
  • 9
  • 11
  • 3
    This solution worked great for me and is infinitely simpler than the alternatives here. I think yarn can mangle npm if the install gets a permissions/access error during upgrade/install. – Slbox Aug 30 '19 at 17:46
  • This should be the correct answer. The other method can break things and doesn't address what really needs to happen, which is telling yarn how to use node. Update: Wait, I still get the above error. :( – Christia Apr 14 '23 at 17:48
65

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

WoJ
  • 27,165
  • 48
  • 180
  • 345
Gangadhar
  • 651
  • 5
  • 2
  • I wish I could double-up this vote for Windows. There's a gotcha: The AppData directory was hidden by default, so I didn't think it was actually installed at this location. – Ringo Dec 06 '16 at 19:02
  • 10
    On windows just _repair_ no need to reinstall – MotKohn May 19 '17 at 06:11
  • 2
    @samayo On Windows where you install there is a repair option. Sorry this was a contextual comment. – MotKohn Sep 11 '17 at 15:30
  • 2
    This approach worked for me as well on my 64-bit Windows 8.1 Enterprise laptop. I had to delete both the "npm" as well as the "npm-cache" folders, followed by an uninstall and a new node installation. – Eddie Nov 06 '17 at 23:02
  • Please can somebody provide a full concise and exhaustive tutorial on how to achieve this on Microsoft Windows? – Stephan Kristyn Jul 05 '21 at 02:36
  • i deleted npm and npm-cache from c:/user/myusername/appData/Roaming also by default it was hidded so first show hidden folders and then reinstaled node – Bogdan Feb 08 '22 at 09:48
58

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:

  1. sudo apt-get purge nodejs --auto-remove and sudo apt-get purge npm --auto-remove
  2. whereis node: remove all the versions of node, one at a time. Repeat until this command returns a blank after node:.
  3. sudo apt-get install nodejs
  4. node --version: should return ... no such file or directory
  5. 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.
  6. sudo apt-get install npm
  7. npm --version: it will use the nodejs installed by apt and work correctly.
Schmudde
  • 1,078
  • 1
  • 11
  • 19
  • 4
    I found this answer is useful for Ubuntu 20.x.x in aws.... – Shurvir Mori Nov 30 '20 at 06:16
  • 2
    Step number 1 did the trick, awesome. Ubuntu 20.04 – yehanny Feb 04 '21 at 02:42
  • 11
    having a problem at step #3 on ubuntu 20.10 - as soon as I execute step 2 node starts to exist – ligi Apr 20 '21 at 10:34
  • 2
    This answer helped me tremendously. For anyone using virtual machines with Ubuntu 20.04, I successfully installed latest node (v 16) installed with npm (v 7) using nvm. https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html – ali Jul 08 '21 at 10:13
  • 2b: do the same with npm? – Gauthier Aug 10 '21 at 07:02
  • @Gauthier - Yes, do the same with npm (step 5). – Schmudde Aug 12 '21 at 13:14
  • in my case; step 1 whereis node still return one entry in /usr/local/bin/node; which i deleted using sudo rm /usr/local/bin/node – Adeel Raza Azeemi Nov 12 '21 at 09:55
  • On Linux Mint after installing node, both node and nodejs respond with the same version (v10.19.0), this is because node installation also creates a link called nodejs. However npm returns a different version (6.14.4) which I assume is ok. – Snake Sanders Dec 22 '21 at 20:27
  • On the second step, nvm could also be a soltuion. – Pavel Fedotov Mar 05 '22 at 00:28
  • 2
    This was useful for me in seeing where the problem was. Instead of uninstalling and re-installing the default Ubuntu version, I just uninstalled the Ubuntu version and installed everything through Node Version Manager (nvm). – Tim Ludwinski Jul 21 '22 at 18:41
47

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.

codewithfeeling
  • 6,236
  • 6
  • 41
  • 53
35

I had the same problem, the way i solved it was by executing

PATH="$PATH"

in terminal, problem was the terminal kept the old path of nodejs instead of using the new one.

darylvickerman
  • 572
  • 5
  • 12
34

On Arch Linux what did the trick for me was:

sudo pacman -Rs npm
sudo pacman -S npm
Telmo Trooper
  • 4,993
  • 1
  • 30
  • 35
  • 2
    I had to use `sudo pacman -Rdd` to remove ignoring the dependencies, but it did not solve the issue for me. Installing semver from the arch packages in Mathias Braun's answer did. – Pierre-Alexis Ciavaldini Apr 17 '18 at 11:19
18

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

pacman -S semver
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
11

Actually, it is taking the reference of previously stored modules.

Solution:Delete the npm-cache/npm folder in the installation directory of nodejs. In windows, it is in C:/User/Username/Appdata/Roaming/npm(or npm_cache). and try to install again.

Same thing to do in any OS.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
Shubham Jaiswal
  • 570
  • 5
  • 11
  • 1
    That's it. I uninstalled node. Then deleted both `npm` and `npm_cache` from `/Appdata/Roaming`. Then installed node again. Seems cache to be blamed there. – Saulius Dec 23 '19 at 12:20
11

Just uninstall node js then reinstall it using nvm. Your problem will be solved. I am a debian 10 user.

To install nvm, follow the instructions in the latest nvm installation script or run the following (potentially out of date) command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

after executing the command. close your terminal and reopen then run this command to install node js latest version.

nvm install --lts

now check the node version by running node -v

Bulmenisaurus
  • 47
  • 3
  • 7
Mahedi Hasan Durjoy
  • 1,031
  • 13
  • 17
  • This was the fix for me on a Raspbian v10. None of the other solutions worked. – pholcroft Jan 24 '23 at 22:07
  • I think this should be the correct solution, because like the official site said: ["We strongly recommend using a Node version manager like nvm to install Node.js and npm. We do not recommend using a Node installer, since the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally."](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) then after installing nvm, you can install the latest long term support version just with "nvm install --lts". – dmaon May 30 '23 at 16:38
10
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*

sudo apt-get purge nodejs npm
sudo apt autoremove

Then install node and npm

original answer

Mohamed Farouk
  • 957
  • 1
  • 13
  • 29
  • Duplicate from https://askubuntu.com/questions/1152570/npm-cant-find-module-semver-error-in-ubuntu-19-04 – colidyre Mar 12 '23 at 10:55
9

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

zeeawan
  • 6,667
  • 2
  • 50
  • 56
  • Worked for me _after_ purging the OS (Ubuntu) versions of `nodejs` and `npm`, which are 5 major versions behind the official installer versions. – Auspex Jul 25 '22 at 13:26
7

Just make sure semver is installed: npm install -g semver

Jérôme Beau
  • 10,608
  • 5
  • 48
  • 52
  • 12
    npm is not working, so you can't install semver through npm. Best solution is to use yarn to install npm or missing packages – NFpeter May 07 '19 at 13:07
  • @NFpeter I had exactly the same problem as stated in the question and fixed it this way, so npm did work (in my case at least). – Jérôme Beau May 08 '19 at 14:05
7

For me, this happened after I installed yarn globally. To resolve this issue, install npm using yarn and done.

yarn global add npm
the_haystacker
  • 1,585
  • 18
  • 20
6

I got same error and I solved it.

delete package-lock.json file and node_modules folder then npm install

Justin Joseph
  • 3,001
  • 1
  • 12
  • 16
6

For arch linux

sudo pacman -Rsc -n nodejs
sudo pacman -Sy nodejs
sudo pacman -Sy npm

Found here: https://github.com/npm/npm/issues/15558

Geoff Langenderfer
  • 746
  • 1
  • 9
  • 21
5

On Windows, downloading Node's MSI again and doing a 'Repair' worked for me.

Sornakumar
  • 432
  • 5
  • 20
5

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

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

Wireblue
  • 1,329
  • 1
  • 14
  • 24
5

This worked for me on Ubuntu (latest version dated Oct/2020)

I had to first get code from the bash source:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

This got the latest version of node which updated my libraries and got rid of the 'semver' error.

Snowcat
  • 470
  • 8
  • 16
4

First you can try close current terminal tab and open new its work fine

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33005431) – Al Foиce ѫ Oct 27 '22 at 08:47
  • This is the answer. lol – Allen Gingrich Nov 17 '22 at 00:28
3

just remove your node_modules

rm -rf node_modules

than

yarn

or

npm install
Rashid Iqbal
  • 1,123
  • 13
  • 13
3

Just a reminder of executable npm execute via node env:

xb@dnxb:/tmp$ type -a npm
npm is /usr/bin/npm
npm is /bin/npm
xb@dnxb:/tmp$ realpath /usr/bin/npm /bin/npm
/usr/share/npm/bin/npm-cli.js
/usr/share/npm/bin/npm-cli.js
xb@dnxb:/tmp$ 
xb@dnxb:/tmp$ head -1 /usr/share/npm/bin/npm-cli.js
#!/usr/bin/env node

I can check which node is chosen by type -a, the first line has the most priority, i.e. I can get same error if I run /usr/local/bin/node /usr/share/npm/bin/npm-cli.js, but no error if I run /usr/bin/node /usr/share/npm/bin/npm-cli.js:

xb@dnxb:/tmp$ type -a node
node is /usr/local/bin/node
node is /usr/bin/node
node is /bin/node
xb@dnxb:/tmp$ realpath /usr/local/bin/node
/usr/local/bin/node
xb@dnxb:/tmp$ realpath /usr/bin/node
/usr/bin/node
xb@dnxb:/tmp$ realpath /bin/node
/usr/bin/node
xb@dnxb:/tmp$ 

There are 2 unique node exe based on realpath. If you have the similar case, then you need to find out how to remove the undesired/broken node exe, e.g. sudo rm /usr/local/bin/node or manipulate env $PATH.

林果皞
  • 7,539
  • 3
  • 55
  • 70
2

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.

Jörn Hees
  • 3,338
  • 22
  • 44
cedric
  • 61
  • 1
2

i was getting an error saying Permission Denied after running any 'ng' command (ng --version). I googled for a while and tried clearing npm cache npm cache verify, uninstalling my global angular cli (npm uninstall -g @angular/cli) and reinstalling Angular/cli (npm install -g @angular/cli) etc.. but it would give an error say its already installed. but the node_modules folder here wouldn't have any angular folder.. reinstalled node even then restarted my computer.

ANSWER: Finally I found that the ng.cmd and ng.ps1 files in C:\Users\JaGoodwin\AppData\Roaming\npm\ here were still there (in npm folder).. even though I did npm uninstall -g @angular/cli. those files were causing ng (angular/cli) to think it was still installed. i deleted those files then npm install -g @angular/cli@8.3.29 (version i need) I then removed my projects node_modules and then ran npm install and now can run my angular project using ng serve.

enter image description here

C:\Users\JaGoodwin\AppData\Roaming\npm\

Find this by folder searching %APPDATA% in your windows search bar.

2

Start fresh.

brew uninstall --force node
brew install node
Grant
  • 5,709
  • 2
  • 38
  • 50
2

Just delete (or rename) the cloned repository's version of semver folder: "gitClonedRepository/App/node_modules/semver"

and copy the "semver" folder from "C:\Program Files\nodejs\node_modules\npm\node_modules\semver"

into the application's node_modules folder.

(if you're on Windows, othervise it must be located somewhere in /usr/local/lib/node_modules).

Ivan Silkin
  • 381
  • 1
  • 7
  • 15
2

All I needed was sudo rm -rf node_modules/ in the directory I was working in. This happened after I updated my node version with n lts

Jacob Solawetz
  • 358
  • 3
  • 5
2

Nevermind install Yarn.Performs parallel installation resulting in better speed and performance from npm

 sudo apt remove yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - 
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install yarn -y
2

This issue usually comes when node js and npm versions are not compatible. To fix this in Ubuntu (my version was 20)

  1. Uninstall node js and npm.
    • apt remove npm
    • apt remove nodejs
    • which node (it will return node js files path)
    • Delete node directory
  2. Install NVM
  3. Install node
    • nvm install e.g. nvm install 8.16
    • Above command will itself install node js and its compatible NPM.
Vineet Sajwan
  • 156
  • 2
  • 8
1

I finally figured this out! Yes, you have to uninstall/delete all files and reinstall. BUT SOME OF THE FILE PATHS ARE TOO LONG TO DELETE DURING THE UNINSTALL PROCESS. The file paths are so long in Node that they may not be able to be deleted. You have to rename the file paths.

After uninstalling Node, use Command Prompt, navigate to ...\Appdata\roaming\ (use the path from the error message). Try to delete the folder with del npm. Then, if it doesn't allow you to delete a folder, start renaming the folders in the file path in the next error message to "a" or something short. You may have to do this for multiple folders along the path. Then you should be able to delete! Then reinstall node and it should work.

The Windhover
  • 312
  • 3
  • 16
1

For me, it happened while upgrading to gulp 4 from gulp 3 in my project. So, when I run "gulp watch" command, it was throwing me same error.

It's probably due to version mismatch as compared to my globally installed gulp.

So, either upgrading gulp with "-g" global flag would help, or else I followed this below

However, I used "./node_modules/.bin/gulp watch" in my project. This ensures that all the dependencies that gulp needs are taken from node_modules only.

master_dodo
  • 1,203
  • 3
  • 20
  • 31
1

On WSL (so, ~Ubuntu), I faced this problem after having installed both, nodejs and npm through apt, then updated Node using n.

I was able to resolve it by completely removing apt's installation of npm: sudo apt purge npm.

Cedric Reichenbach
  • 8,970
  • 6
  • 54
  • 89
0

Just remove 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 unnistal, try to follow this:

Uninstalling

So sad to see you go.

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

sudo make uninstall More Severe Uninstalling

Usually, the above instructions are sufficient. That will remove npm, but leave behind anything you've installed.

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

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

npm explore npm -g -- sh scripts/clean-old.sh npm uses two configuration files, one for per-user configs, and another for global (every-user) configs. You can view them by doing:

npm config get userconfig # defaults to ~/.npmrc npm config get globalconfig # defaults to /usr/local/etc/npmrc Uninstalling npm does not remove configuration files by default. You must remove them yourself manually if you want them gone. Note that this means that future npm installs will not remember the settings that you have chosen.

Rodmentou
  • 1,610
  • 3
  • 21
  • 39
  • Updated my answer. Try it now. If it does not work, test something for me. Copy the package.json to another folder and try to use npm install. – Rodmentou Nov 23 '15 at 12:16
  • 1
    Can you paste your package.json, please? – Rodmentou Nov 23 '15 at 12:21
  • { "name": "workspace", "version": "0.0.0", "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { "body-parser": "~1.13.2", "bson": "^0.2.22", "cookie-parser": "~1.3.5", "debug": "~2.2.0", "express": "~4.13.1", "hbs": "~3.1.0", "monk": "^1.0.1", "morgan": "~1.6.1", "serve-favicon": "~2.3.0" }, "engines": { "node": "4.2.2" } } – user2447562 Nov 23 '15 at 12:34
  • Have you tried to run npm install with your package.json in another folder? – Rodmentou Nov 23 '15 at 12:39
  • i have to uninstall to node.js, after install node.js....i have to create sampleapplication using mean.that time i have to install npm intall command,but i am getting same error...please give some solution to me.... – user2447562 Nov 24 '15 at 04:45
0

In my case, simply re-running brew install yarn fixed the problem.

jack4it
  • 121
  • 1
  • 5
0

I faced with same trouble after brew installs yarn on my MacOs Sierra 10.12.6. (And the first try of installation fall after brew update self with a message " Homebrew must be run under Ruby 2.3! You're running 2.0.0. (RuntimeError)". So I re-run it.)

So I use n manager to reinstall npm.

  • switch to another node version (for my case to 8.0) by "n" command with empty parameters
  • or install new by "n x.x.x" where x.x.x the node version number (i need 6.9.1)
  • delete working version by "n rm x.x.x" where x.x.x the node version number. use sudo if need
  • install working version by "n x.x.x" where x.x.x the node version number. use sudo if need
  • switch by to the working version of node. (see first step for reference)

I think the trouble can be caused that node was installed under sudo for case.

Larest
  • 326
  • 1
  • 3
  • 15
0

I had the same issue installing on AWS Linux. I had to install it with sudo. So to get around this I followed step 3 from this article (making sure to get the latest version of node)

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

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

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

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

After that I was able to do an npm install with no issues.

Jerinaw
  • 5,260
  • 7
  • 41
  • 54
0

I faced this issues while running project on higher version of cli. To solve this issue you can simply comment out @angular-devkit/build-angular module and again you have to reinstall it through

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

sachin
  • 222
  • 2
  • 3
0

If you happen to get a 'semver' typescript error for the 'import' keyword, check if your file's extension is js instead of ts

Nati Kamusher
  • 533
  • 5
  • 9
0

I encountered this Cannot find module 'semver' error while running npm install in WSL1 under Windows 10, with Ubuntu 22.04.2 LRS (jammy) as the Linux installation.

Using strace to see what syscalls were made, I found that Node.js was looking for /usr/share/nodejs/npm/node_modules/semver/package.json, which didn't exist. However, that module does appear to exist at the top level, in /usr/share/nodejs/semver/package.json. After some experimentation, I found that adding the top-level directory to Node's search path appears to fix the problem. This worked for me:

NODE_PATH=/usr/share/nodejs npm install

Therefore, I've added the environment variable setting to my ~/.bashrc file:

export NODE_PATH=/usr/share/nodejs
-2

Just check your preinstall scripts if you have one. Sometimes to restrict the versions of node and npm one needs to run a project.

If that's the case you need to install semver manually via npm install -g semver

Mr94
  • 143
  • 1
  • 15