【问题标题】:npm update -g on Windows failsWindows 上的 npm update -g 失败
【发布时间】:2020-03-06 05:57:35
【问题描述】:

我在这里扯头发。当我从非提升的命令提示符运行 npm update -g 时,我得到这个:

npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Program Files\nodejs\node_modules\.staging
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.staging'
npm ERR!  [OperationalError: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.staging'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_modules\.staging'] {
npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'mkdir',
npm ERR!     path: 'C:\\Program Files\\nodejs\\node_modules\\.staging'
npm ERR!   },
npm ERR!   stack: "Error: EPERM: operation not permitted, mkdir 'C:\\Program Files\\nodejs\\node_modules\\.staging'",
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'C:\\Program Files\\nodejs\\node_modules\\.staging'
npm ERR! }
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\[MY_USERNAME]\AppData\Roaming\npm-cache\_logs\2020-03-05T20_50_19_641Z-debug.log

它为什么要在C:\Program Files\nodejs\node_modules\ 下创建一个.staging 目录??它应该在C:\Users\[MY_USERNAME]\AppData\Roaming\npm\node_modules 下创建它。那是我的模块安装的地方。我不需要以管理员身份运行命令。

编辑:好的,我以管理员身份运行了命令,即使它没有任何意义,你猜怎么着?它仍然拒绝这样做!

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.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\[MY_USERNAME]\AppData\Roaming\npm-cache\_logs\2020-03-05T21_23_18_719Z-debug.log

看起来它正在尝试更新 npm 本身。我删除 npm.cmd 并...

'npm' is not recognized as an internal or external command, operable program or batch file.

哦,对了!我多么愚蠢!好吧,现在我没有 npm 命令,必须重新安装 Node.js。

更新:修复安装了 NodeJS,然后返回管理员命令提示符并...

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.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\[MY_USERNAME]\AppData\Roaming\npm-cache\_logs\2020-03-05T21_56_28_029Z-debug.log

究竟是什么……?!没有人能回答这个问题吗?!我应该完全擦除我的 Node 安装吗??

【问题讨论】:

  • 以管理员身份在 cmd 中运行

标签: node.js windows npm


【解决方案1】:

EPERM:不允许操作 => 您的用户无法创建文件夹

解决方案:

1- 以管理员身份打开 cmd(右键单击选项 cmd)

【讨论】:

  • 当我更新属于我的软件包时,为什么我必须以管理员身份运行它?这没有任何意义。
  • -g == global => 所有用户
  • 从什么时候开始的?如果这是真的,那么为什么 -g 在正常情况下会导致它安装到 C:\Users[user]\AppData\Roaming\npm?
猜你喜欢
  • 2021-05-15
  • 2017-09-27
  • 1970-01-01
  • 2022-11-04
  • 2015-09-24
  • 2015-08-26
  • 1970-01-01
  • 1970-01-01
  • 2015-03-30
相关资源
最近更新 更多