Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't update npm packages: ERR! code EEXIST

Tags:

node.js

npm

nvm

I'm trying to to upgrade npm packages via

npm update -g

But, I get this error:

npm ERR! path C:\Program Files\nodejs\npm
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Program Files\nodejs\npm: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm
npm ERR! Move it away, and try again.

I've googled but none of the solutions work. One sadi to remove the npm.cmd and npm files from here:

C:\Program Files\nodejs\

I tried that, but it fails as npm is now missing.

That folder, C:\Program Files\nodejs\, is actually a shortcut pointing to

C:\Users\lthurman\AppData\Roaming\nvm\v8.11.1

I'm using nvm to manage my node installations, any ideas on how to fix this?

Thanks

like image 212
Lazloman Avatar asked May 22 '19 20:05

Lazloman


2 Answers

To resolve this issue I took the following steps

Where [userName] is your Windows user name -- [nodeVer] is your current version of Node, or the one that is giving you issues using NVM

Delete these four files:

C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npm
C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npm.cmd
C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npx
C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\npx.cmd

Then in C:\Users\[userName]\AppData\Roaming\nvm\[nodeVer]\node_modules\, rename the npm directory to npm_old

Open up your console of choice -- run as admin if necessary -- and navigate into the \npm_old\bin directory then install NPM at latest (or replace latest w/a version of your choosing) using the command below:

node npm-cli.js i -g npm@latest

Clean-up by deleting the npm_old directory from earlier. Now all should be good to go...I hope!

like image 106
Rockin4Life33 Avatar answered Sep 17 '22 20:09

Rockin4Life33


Try doing this below command after deleting the folder C:\Users\xxx\AppData\Roaming\npm, C:\Users\xxx\AppData\Roaming\npm-cache.

npm install -g npm@latest
like image 31
Avinash Singh Avatar answered Sep 16 '22 20:09

Avinash Singh