簡體   English   中英

在 Mac OS 10.13 上安裝 Angular

[英]Installing Angular on Mac OS 10.13

我正在嘗試按照快速入門在本地運行 Angular(在 MacOS 10.13.6 上)。 使用第一個命令,我已經得到了一些錯誤:

npm install -g @angular/cli

Output:

npm ERR! path /usr/local/lib/node_modules/@angular/cli/node_modules/socks
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli/node_modules/socks'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/@angular/cli/node_modules/socks']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/@angular/cli/node_modules/socks\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/usr/local/lib/node_modules/@angular/cli/node_modules/socks' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
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 (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2019-03-12T23_55_12_063Z-debug.log

使用 sudo 運行會得到以下信息:

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/.node-gyp'
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" "--module_name=fse" "--module_path=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64" "--napi_version=3" "--node_abi_napi=napi"
gyp ERR! cwd /usr/local/lib/node_modules/@angular/cli/node_modules/fsevents
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node --module_name=fse --module_path=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64 --napi_version=3 --node_abi_napi=napi' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:189:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:970:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
node-pre-gyp ERR! System Darwin 17.7.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/@angular/cli/node_modules/fsevents
node-pre-gyp ERR! node -v v10.15.3
node-pre-gyp ERR! node-pre-gyp -v v0.10.3
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node --module_name=fse --module_path=/usr/local/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64 --napi_version=3 --node_abi_napi=napi' (1)

我的節點版本是 LTS (10.15.3)。 知道是什么原因造成的,以及如何讓 angular 在 Mac 上運行?

您將需要在node_modules目錄中具有寫許可權:

sudo chown -R $(whoami) ~/.npm

從長遠來看,在安裝npm時運行sudo會給您帶來問題,因此只需運行上面的命令即可。

npm拋出沒有sudo的錯誤

sudo npm install -g @angular/cli

以sudo權限運行,您應該會很好。

/usr/local文件夾需要root權限,請嘗試使用sudo安裝它:

sudo npm install -g @angular/cli

正如評論中提到的,使用 sudo 不是一個好習慣,我必須運行以下 3 個命令來獲得相關目錄的所有權:

sudo chown -R $(whoami) ~/.npm  
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin

現在我可以全局安裝 Angular CLI(或任何其他節點包),而不需要 sudo。

暫無
暫無

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

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