【发布时间】:2020-04-05 14:35:09
【问题描述】:
上个月我安装了 node 10.16.3 LTS,因为它没有最新的 npm 版本,所以我使用这个官方指南更新了它:https://docs.npmjs.com/try-the-latest-stable-version-of-npm(选项 2):
- 删除了 %ProgramFiles%\nodejs\npm 和 %ProgramFiles%\nodejs\npm.cmd
- 将“npmrc”文件从 %ProgramFiles%\nodejs\node_modules\npm 移动到 %appdata%\npm\node_modules\npm
今天,在我安装了“create-react-app”之后,npm 向我显示了 npm 的新次要版本可用 6.11.3 -> 6.12.0 并且我可以更新它的消息。
我运行了“npm install -g npm@latest”,但这只是给我带来了一堆错误:
C:\Users\Wladyslaw\AppData\Roaming\npm\npx -> C:\Users\Wladyslaw\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Users\Wladyslaw\AppData\Roaming\npm\npm
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'C:\Users\Wladyslaw\AppData\Roaming\npm\npm'
npm ERR! { [Error: EPERM: operation not permitted, open 'C:\Users\Wladyslaw\AppData\Roaming\npm\npm']
npm ERR! cause:
npm ERR! { Error: EPERM: operation not permitted, open 'C:\Users\Wladyslaw\AppData\Roaming\npm\npm'
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: 'C:\\Users\\Wladyslaw\\AppData\\Roaming\\npm\\npm' },
npm ERR! stack:
npm ERR! 'Error: EPERM: operation not permitted, open \'C:\\Users\\Wladyslaw\\AppData\\Roaming\\npm\\npm\'',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: 'C:\\Users\\Wladyslaw\\AppData\\Roaming\\npm\\npm' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Wladyslaw\AppData\Roaming\npm-cache\_logs\2019-10-17T19_35_58_442Z-debug.log
现在我什至无法运行“npm -v”,它以某种方式删除了我的 npm 文件夹并只显示这条消息:
bash: /c/Users/Wladyslaw/AppData/Roaming/npm/npm: No such file or directory
有没有办法在不重新安装整个 Node.js 的情况下修复这种损坏的 npm 安装?
谢谢
【问题讨论】:
-
所以我不得不完全重新安装 Node.js。显然上面提到的指南有些过时了。最新的节点安装程序根本没有将 'C:\Program Files (x86)\nodejs' 放在 PATH 上,只有 'C:\Users\
\AppData\Roaming\npm'。刚刚运行相同的“npm install -g npm@latest”,现在我有了最新的 npm