簡體   English   中英

無法使用 npm errno -4048 package.json 安裝 angular cli

[英]Unable to install angular cli with npm errno -4048 package.json

我嘗試使用 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*

從您的錯誤日志來看,安裝軟件包時似乎存在一些權限問題。 您可以通過兩種方式具體解決此問題。

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命令。

1) 卸載節點 2) 從 [ https://nodejs.org/en/][1]下載最新版本的節點。 3)安裝節點js

嘗試在 Windows 10 上使用 npm 安裝 Yeoman 時,我遇到了類似的問題。 罪魁禍首原來是我機器上安裝的 McAfee AV 軟件。 McAfee 似乎正在掃描 npm 試圖對 json 文件所做的更改,並且作為掃描例程的一部分,阻止了重命名的發生。 這導致 npm 引發 4048 錯誤,類似於輸出中的錯誤。

為了解決這個問題,我:

  1. 卸載 McAfee 並重新啟動我的機器,使其恢復到 Microsoft 的內置安全軟件。
  2. 重新運行 npm install 命令,它工作正常。

或者,您可以更改 AV 軟件的設置,以不主動檢查 node_modules 文件夾的文件更改。 這有望讓您的 AV 軟件保持安裝狀態,並且 npm 命令也能正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM