【问题标题】:Unable to install angular cli with npm errno -4048 package.json无法使用 npm errno -4048 package.json 安装 Angular cli
【发布时间】:2018-06-13 01:51:51
【问题描述】:

我尝试使用 npm 安装 angular cli。但是在执行命令 npm install -g @angular/cli 时出现以下错误。 我不是以管理员身份执行此命令,而是以用户身份执行此命令。

D:\AngularWorkstation>npm install -g @angular/cli
npm WARN sass-loader@6.0.6 requires a peer of node-sass@^4.0.0 but none is installed. You must install peer dependencies yourself.

npm ERR! path **D:\node_modules\node_modules\@angular\cli\node_modules\which\package.json.365294863
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename
npm ERR! Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\@angular\cli\node_modules\which\package.json.365294863' -> 'D:\node_modules\node_modules\@angular\cli\node_modules\which\package.json'
npm ERR!  { Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\@angular\cli\node_modules\which\package.json.365294863' -> 'D:\node_modules\node_modules\@angular\cli\node_modules\which\package.json'
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\@angular\cli\node_modules\which\package.json.365294863' ->** 'D:\node_modules\node_modules\@angular\cli\node_modules\which\package.json'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'rename',
npm ERR!      path: 'D:\\node_modules\\node_modules\\@angular\\cli\\node_modules\\which\\package.json.365294863',
npm ERR!      dest: 'D:\\node_modules\\node_modules\\@angular\\cli\\node_modules\\which\\package.json' },
npm ERR!   stack: 'Error: EPERM: operation not permitted, rename \'D:\\node_modules\\node_modules\\@angular\\cli\\node_modules\\which\\package.json.365294863\' -> \'D:\\node_modules\\node_modules\\@angular\\cli\\node_modules\\which\\package.json\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'rename',
npm ERR!   path: 'D:\\node_modules\\node_modules\\@angular\\cli\\node_modules\\which\\package.json.365294863',
npm ERR!   dest: 'D:\\node_modules\\node_modules\\@angular\\cli\\node_modules\\which\\package.json',
npm ERR!   parent: '@angular/cli' }
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:\Users\techno\AppData\Roaming\npm-cache\_logs\2018-01-03T09_14_35_602Z-debug.log

*PS:我使用的是 Windows10 操作系统。我还尝试将 npm 全局路径更改为“D:\node_modules”以检查是否是由于权限问题。但是输出是一样的。

node --version : v7.7.2
npm --version : 4.1.2*

【问题讨论】:

标签: node.js angular npm angular-cli


【解决方案1】:

从您的错误日志来看,安装软件包时似乎存在一些权限问题。您可以通过两种方式具体解决此问题。

1) 如果您尝试全局安装软件包,则必须以管理用户身份运行 npm install <pkg_name> -g 命令或使用 sudo npm install <pkg_name> -g 命令。

要全局安装npm-packages,您可以按照以下步骤操作:

  • 以管理用户身份运行命令提示符。
  • 运行npm install <pkg_name> -g

2) 您应该尝试转到 Windows 资源管理器中的顶级文件夹,右键单击“获取更多信息”选项,然后转到权限部分,给自己所有权限,并告诉它以递归方式应用它们。

  • 或者只是你可以转到指定的npm working directory 并编辑权限部分并允许当前用户的所有权限,并将所有递归目录的所有者也更改为它自己。

  • 然后再次启动 Windows。

注意:如果您在本地安装npm-package,那么您应该在本地项目目录中,可以尝试运行sudo npm install <pkg-name> 命令来安装所需的包。使用sudo 的目的是改变你的所有者权限,这样你就可以让你的当前用户被授权运行npm 命令。

【讨论】:

    【解决方案2】:

    1) 卸载节点 2) 从 [https://nodejs.org/en/][1] 下载最新版本的节点。 3)安装节点js

    【讨论】:

      【解决方案3】:

      尝试在 Windows 10 上使用 npm 安装 Yeoman 时,我遇到了类似的问题。原来,罪魁祸首是我机器上安装的 McAfee AV 软件。 McAfee 似乎正在扫描 npm 试图对 json 文件进行的更改,并且作为扫描例程的一部分,阻止了重命名的发生。这导致 npm 引发 4048 错误,类似于您的输出中的错误。

      为了解决这个问题,我:

      1. 卸载 McAfee 并重新启动我的机器,使其恢复为 Microsoft 的内置安全软件。
      2. 重新运行 npm install 命令,它工作正常。

      或者,您可以更改 AV 软件的设置,使其不主动检查 node_modules 文件夹的文件更改。这有望让您的 AV 软件保持安装状态,并且 npm 命令也可以正常工作。

      【讨论】:

        猜你喜欢
        • 2015-08-31
        • 1970-01-01
        • 2018-05-20
        • 2023-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-27
        相关资源
        最近更新 更多