简体   繁体   English

无法更新 npm 包:ERR! 代码 EEXIST

[英]Can't update npm packages: ERR! code EEXIST

I'm trying to to upgrade npm packages via我正在尝试通过以下方式升级 npm 包

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:从这里删除 npm.cmd 和 npm 文件的一个萨迪:

C:\Program Files\nodejs\

I tried that, but it fails as npm is now missing.我试过了,但它失败了,因为现在缺少 npm。

That folder, C:\\Program Files\\nodejs\\, is actually a shortcut pointing to那个文件夹,C:\\Program Files\\nodejs\\,实际上是一个指向

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?我正在使用 nvm 来管理我的节点安装,关于如何解决这个问题的任何想法?

Thanks谢谢

在删除文件夹C:\\Users\\xxx\\AppData\\Roaming\\npmC:\\Users\\xxx\\AppData\\Roaming\\npm-cache后尝试执行以下命令。

npm install -g npm@latest

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其中 [userName] 是您的 Windows 用户名 -- [nodeVer] 是您当前的 Node 版本,或者是使用 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然后在C:\\Users\\[userName]\\AppData\\Roaming\\nvm\\[nodeVer]\\node_modules\\ ,将npm目录重命名为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:打开您选择的控制台——如有必要,以管理员身份运行——并导航到\\npm_old\\bin目录,然后使用以下命令安装最新的 NPM(或替换最新的 W/A 版本):

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

Clean-up by deleting the npm_old directory from earlier.通过删除之前的npm_old目录进行清理。 Now all should be good to go...I hope!现在一切都应该好了……我希望!

It will fixed it by forcing the install with --force它将通过使用--force强制安装来修复它

npm install -g npm@latest --force

Uninstall old version first先卸载旧版本

npm uninstall -g your-package-name

install the latest安装最新的

npm install -g your-package-name@latest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM