【问题标题】:Installing Angular on Mac OS 10.13在 Mac OS 10.13 上安装 Angular
【发布时间】:2019-08-03 13:43:26
【问题描述】:

我正在尝试按照quickstart 在本地运行 Angular(在 MacOS 10.13.6 上)。使用第一个命令,我已经得到了一些错误:

npm install -g @angular/cli

输出:

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-pre-gyp 错误与尚未完全适用于 mac 的 npm 包相关。应用程序将正常运行,请耐心等待更新的软件包出来。

标签: node.js angular macos npm


【解决方案1】:
sudo npm install -g @angular/cli

使用 sudo 权限运行,你应该很好。

【讨论】:

  • 不确定。我会试着在我的机器上做,然后告诉你。
  • @Pim 你可以试试这个Stackover flow
  • 使用 sudo 不是好的做法。然后它会在每次安装软件包时要求您使用 sudo。我昨天遇到了这个问题
【解决方案2】:

/usr/local文件夹需要root权限,请尝试使用sudo安装:

sudo npm install -g @angular/cli

【讨论】:

  • 使用 sudo 不是好的做法。然后它会在每次安装软件包时要求您使用 sudo。我昨天遇到了这个问题
【解决方案3】:

您将需要 node_modules 目录中的写入权限:

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

安装npm时运行sudo,从长远来看会给你带来问题,所以只需运行上面的命令。

npm throws error without sudo

【讨论】:

  • 但我需要将写入权限授予/usr/local/lib/node_modules
猜你喜欢
  • 2018-03-30
  • 2018-12-20
  • 2019-03-01
  • 2018-10-19
  • 2018-11-27
  • 2015-02-04
  • 2018-03-01
  • 2018-05-24
  • 1970-01-01
相关资源
最近更新 更多