npm安装错误 "请尝试以root/Administrator身份再次运行此命令。"

4

我刚刚把我的node升级到版本v6.11.3,npm的版本是5.4.1。

我正在尝试进行以下操作:

npm install 

或任何npm安装,例如

npm install nodemon

并且遇到了这个问题。

 npm WARN deprecated pug@0.1.0: Please update to the latest version of pug, at time of writing that is pug@2.0.0-alpha6
 npm WARN deprecated pug-loader@0.0.0: Please use pug-load for pug-loader@<=1.0.2.
 npm ERR! path C:\Users\project\node_modules\fsevents\node_modules\aws-sign2\package.json
 npm ERR! code EPERM
 npm ERR! errno -4048
 npm ERR! syscall unlink
 npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\project\node_modules\fsevents\node_modules\aws-sign2\package.json'
 npm ERR!     at Error (native)
 npm ERR!  { Error: EPERM: operation not permitted, unlink 'C:\Users\project\node_modules\fsevents\node_modules\aws-sign2\package.json'
 npm ERR!     at Error (native)
 npm ERR!   stack: 'Error: EPERM: operation not permitted, unlink \'C:\\Users\\project\\node_modules\\fsevents\\node_modules\\aws-sign2\\package.json\'\n    at Error (native)',

 npm ERR!   errno: -4048,
 npm ERR!   code: 'EPERM',
 npm ERR!   syscall: 'unlink',
 npm ERR!   path: 'C:\\Users\\project\\node_modules\\fsevents\\node_modules\\aws-sign2\\package.json' }
 npm ERR!
 npm ERR! Please try running this command again as root/Administrator.

 npm ERR! A complete log of this run can be found in:
 npm ERR!     C:\Program\_logs\2017-09-07T21_55_47_482Z-debug.log

我已经搜索并尝试了很多不同的方法,例如

 npm cache clean 

但是遇到这个问题。
 npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify'
 instead.
 npm ERR!
 npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.

 npm ERR! A complete log of this run can be found in:
 npm ERR!     C:\Program\_logs\2017-09-07T22_03_49_893Z-debug.log

我不确定如何解决这个问题,才能够运行我的nodemon而不是nodemon bin/www。


请尝试以管理员身份打开命令提示符,并运行该命令。 - JohnnyAW
如果在Unix系统上:sudo npm install - fdelia
3个回答

6

在安装任何软件包时,尝试使用--no-optional。这对我有用。
npm install nodemon --no-optional


2
今天我遇到了完全相同的问题。然后我安装了yarn。
npm install -g yarn

然后运行

yarn install

这告诉我以下内容:
info fsevents@1.1.2: The platform "win32" is incompatible with this module.
info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.

所以,Yarn 能够处理这个问题,并且对我有效。

我认为问题出在npm版本上。我通过回退到之前的npm版本5.2.0来解决了这个问题,现在它又可以正常工作了。 - Tenz

2

你可能以管理员身份运行了原始的node安装程序。因此,现在管理员拥有全局node_modules目录。

在Windows上:

  • 右键单击cmdpowershell应用程序
  • 选择“以管理员身份打开”
  • 尝试在该特定命令窗口中运行npm install

在OSX或Linux上,请使用sudo

sudo npm install

我按照你描述的做了,但仍然遇到同样的问题。我在想这是否是由于fsevents引起的。 - Tenz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接