如何解决无法将 npm 从 6.14.8 更新到 7.3;删除 npm.cmd、npx.cmd 和 npm 会导致更多错误
我一直在尝试使用 Git Bash 中的 npm install -g npm
命令全局更新我的 npm,以使其与 Angular 11 和 Node.js 版本 15.5.0 保持同步。我收到以下错误:
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm.cmd
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! Remove the existing file and try again,or run npm
npm ERR! with --force to overwrite files recklessly.
我从 nodejs
中删除了文件并尝试重新安装,但收到另一个关于 npx.cmd
的错误。我删除了该文件,尝试安装,但收到关于 npm 文件的错误。
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npx.cmd
npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npx.cmd
npm ERR! Remove the existing file and try again,or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm
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! Remove the existing file and try again,or run npm
npm ERR! with --force to overwrite files recklessly.
删除它们并再次尝试安装 npm
后,Git Bash 不再找到 npm。安装永远不会开始。
bash: /c/Program Files/nodejs/npm: No such file or directory
我尝试从 AppData
的漫游文件夹中删除 npm 文件,但收到以下错误:
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory,lstat 'C:\Users\Yoga 2 Mitchell\AppData\Roaming\npm'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
我也在不同的时间尝试了以下方法:
- 删除
node_modules
并重新安装 npm - 使用 npm 7.3.0 的 Git 存储库创建新的
npm
文件 (?)(我需要再次在线查找建议以澄清/提供更多细节) - 清理缓存
- 卸载并重新安装 Angular 11 CLI 和 Node.js(已针对 LTS 和当前版本进行了尝试)
到目前为止没有任何效果。我在上面列表中尝试的第二种方法能够将其更新到 6.14.10,但是这次尝试返回了似乎影响 Angular 的错误。为了安全起见,我将一切恢复到原始状态。如果我能澄清有关我的问题的任何其他内容,请告诉我。
解决方法
我与另一位开发人员就我收到的错误进行了联系。建议采用以下方法,它可以解决 LTS 的问题:How to completely remove node.js from Windows
LTS 版本允许我更新到 npm 的 6.14.11,但是当我尝试这种方法来安装当前版本时,它仍然是 6.14.11。希望这种方法可以帮助其他遇到类似错误的人。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。