# windows更新npm出错
# 错误提示
npm版本太旧,执行升级版本npm i -g [email protected]
时出现如下错误:
npm ERR! code EEXIST
npm ERR! path D:\Program Files (x86)\node-v13.14.0-win-x64\npm.cmd
npm ERR! Refusing to delete D:\Program Files (x86)\node-v13.14.0-win-x64\npm.cmd: is outside D:\Program Files (x86)\node-v13.14.0-win-x64\node_modules\npm and not a link
npm ERR! File exists: D:\Program Files (x86)\node-v13.14.0-win-x64\npm.cmd
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\dell\AppData\Roaming\npm-cache\_logs\2023-05-16T09_39_51_528Z-debug.log
# 原因
似乎是npm判断机制有关
# 解决
解决办法是把原有相关npm的文件和文件夹全部重命名,然后再用重命名后的npm安装新的npm
进入node目录,重命名如下文件或文件夹:npm
、npm.cmd
、npx
、npx.cmd
、node_modules\npm
,全部加上-old
然后进入重命名后的node_modules\npm-old\bin\
执行:node npm-cli.js i -g npm@latest
即可安装成功
命令行脚本
move npm npm-old
move npm.cmd npm-old.cmd
move npx npx-old
move npx.cmd npx-old.cmd
cd node_modules\
move npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm@latest --force