Npm install-g npm upgrade failed

npm upgrade failed with the following error

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

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\DELL\AppData\Roaming\npm-cache\_logs\2019-02-25T07_12_33_976Z-debug.log

nvm1.1.7 version installed under windows10

//node10.12.0 npm6.4.1
nvm install 10.12.0 
nvm list
* 10.12.0 (Currently using 64-bit executable)
npm -v
6.4.1

I don"t know where the problem led to the failure of the upgrade, and then how to solve it successfully? it still doesn"t work if nvm is uninstalled and installed again, and there is no problem with other installation packages for npm install.

Jul.07,2022

you see, this log is very comprehensive. It refuses to delete the npm under that path, asking you to remove the npm immediately and try Move it away again, and try again.
C:Program Filesnodejsnode_modulesnpm

There is also an error in the

C:Program Filesnodejsnpm.cmd path

delete all the files about npx and npm in the node folder. Execute this: npm install npm@latest-g
mac upgrade error in front of the command sudo

then note that there are many problems with the upgrade of npm. Be careful


install it with system administrator privileges.
as mentioned above, sudo is executed under Mac. By the same token, ok is performed with system administrator commands under windows


There may also be permission problems under

win, by renaming npm.cmd to another, such as npmx.cmd
, and then executing npmx I-g npm.

After renaming, remember to delete npx and npm. Do not change the name in node_modules.

the problem I encountered when upgrading from 6.1.10 to 6.12.1.


I just renamed these files to "1"
npm1.cmd, npm1, npx1, npx1.cmd

and ran:
npm1 update-g

I used this method in https://github.com/coreybutle..., and it worked. You can try

.

result:
$npm1 update-g
C:Program Filesnodejsnpm-> C:Program Filesnodejsnode_modulesnpmbinnpm-cli.js
C:Program Filesnodejsnpx-> C:Program Filesnodejsnode_modulesnpmbinnpx-cli.js

  • npm@6.14.1

added 73 packages from 21 contributors, removed 25 packages and updated 79 packages in 11.671s


if you have installed cnpm (see from=tnpm" rel=" nofollow noreferrer "> Taobao NPM image ), try to execute

cnpm I-g npm

.
Menu