【问题标题】:Difficulty installing Angular CLI on Mac在 Mac 上安装 Angular CLI 很困难
【发布时间】:2020-01-23 00:00:00
【问题描述】:

我正在尝试将 angular 安装到我的 Mac 的全局目录中,但经过几次尝试后至今没有运气。我已经尝试了以下列表:

  • npm install -g @angular/cli
  • npm install -g @angular/cli@latest

How to upgrade Angular CLI to the latest version

https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Can't install Angular CLI

这是错误...

> @angular/cli@8.3.5 postinstall /Users/admin/Desktop/node_modules/@angular/cli
> node ./bin/postinstall/script.js


/Users/admin/Desktop/node_modules/@angular/cli/bin/postinstall/ng-update-message.js:7
const fs = require('fs');
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/admin/Desktop/node_modules/@angular/cli/bin/postinstall/script.js:4:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
npm ERR! Darwin 16.7.0
npm ERR! argv "/Users/admin/.nvm/v0.10.48/bin/node" "/Users/admin/.nvm/v0.10.48/bin/npm" "install" "@angular/cli@latest"
npm ERR! node v0.10.48
npm ERR! npm  v2.15.1
npm ERR! code ELIFECYCLE

npm ERR! @angular/cli@8.3.5 postinstall: `node ./bin/postinstall/script.js`
npm ERR! Exit status 8
npm ERR! 
npm ERR! Failed at the @angular/cli@8.3.5 postinstall script 'node ./bin/postinstall/script.js'.
npm ERR! This is most likely a problem with the @angular/cli package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/postinstall/script.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs @angular/cli
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! 
npm ERR!     npm owner ls @angular/cli
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/admin/Desktop/npm-debug.log

如果我能最好地解决这个问题,我将不胜感激?

【问题讨论】:

  • 你的节点版本是多少?更新后试试。
  • 我想通了,谢谢。我在 v10.16.3 上运行

标签: angular macos npm angular-cli npm-install


【解决方案1】:

试试

sudo npm install -g @angular/cli --unsafe-perm=true --allow-root

【讨论】:

  • 感谢您的输入,我之前尝试过这个命令,但没有成功。
  • 你的 NodeJs 版本是多少??
  • 我已经能够解决这个问题。我最初在:/usr/local/share/.npm 中错误地安装了NodeJs。我基本上不得不删除 .npm 文件夹并重新安装节点和 npm。删除 node_modules 并不是最简单的。
  • 谢谢,我也使用了sudo npm install -g @angular/cli --unsafe-perm=true --allow-root。我在 v10.16.3 上运行
  • 谢谢,这是唯一对我有用的命令。
【解决方案2】:

尝试将您的 Node 和 NPM 版本更新到最新版本。 Angular 8 需要 Node 8.9+ 和 NPM 5.5.1+。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    • 2012-12-08
    • 2021-06-11
    • 2012-06-14
    • 1970-01-01
    • 2012-08-26
    相关资源
    最近更新 更多