首页 > 解决方案 > Mac 无法安装 Angular-CLI

问题描述

我正在尝试安装 Angular-CLI,以便可以使用 Ionic 框架,但是安装不断崩溃并给我一个错误。

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
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/me/.npm/_logs/2019-05-31T09_00_09_770Z-debug.log

我试过通过写来安装它

sudo npm install -g @angular-cli

我也试过通过这个方法安装它: Can't install angular-cli on Mac

对不起,我对此很陌生,所以我不确定我应该提供什么信息。

我已经安装了 Node JS (10.16.0)

我也刚刚安装了 Ionic Framework 和 Cordova,但是每当我尝试打开通过终端创建的项目时,它都会告诉我需要安装 Angular-CLI,一旦我同意安装,我就会收到相同的信息错误如上。

我的 MacOSX 是 10.14.5

编辑:

我已为计算机上的当前用户登录分配了读写权限,但仍然出现错误。当我Ionic lab在终端中运行以打开我的项目时,终端会询问我是否要安装 angular,我写的是 Yes。然后我得到这些错误。

[ng] Could not find module "@angular-devkit/build-angular" from "/Users/me/project".
[ng] Error: Could not find module "@angular-devkit/build-angular" from "/Users/me/project".
[ng]     at Object.resolve (/Users/me/project/node_modules/@angular-devkit/core/node/resolve.js:141:11)
[ng]     at Observable.rxjs_1.Observable [as _subscribe] (/Users/me/project/node_modules/@angular-devkit/architect/src/architect-legacy.js:153:40)
[ng]     at Observable._trySubscribe (/Users/me/project/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:44:25)
[ng]     at Observable.subscribe (/Users/me/project/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:30:22)
[ng]     at /Users/me/project/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:99:19
[ng]     at new Promise (<anonymous>)
[ng]     at Observable.toPromise (/Users/me/project/node_modules/@angular-devkit/architect/node_modules/rxjs/internal/Observable.js:97:16)
[ng]     at RunCommand.runSingleTarget (/Users/me/project/node_modules/@angular/cli/models/architect-command.js:161:86)
[ng]     at RunCommand.runArchitectTarget (/Users/me/project/node_modules/@angular/cli/models/architect-command.js:201:35)
[ng]     at RunCommand.run (/Users/me/project/node_modules/@angular/cli/commands/run-impl.js:14:25)
[ng]     at RunCommand.validateAndRun (/Users/me/project/node_modules/@angular/cli/models/command.js:124:31)
[ng]     at process._tickCallback (internal/process/next_tick.js:68:7)
[ng]     at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
[ng]     at startup (internal/bootstrap/node.js:283:19)
[ng]     at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

[ERROR] ng has unexpectedly closed (exit code 1).

        The Ionic CLI will exit. Please check any output above for error
        details.

标签: node.jsmacosionic-frameworkangular-cli

解决方案


如果这里有人遇到和我一样的问题,基本上我所做的就是我跑了

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

在我的终端中,然后我重新启动了我的电脑。一旦我这样做了,我基本上只是创建了一个新项目,并从那里添加了所有内容(包括 Angular CLI)


推荐阅读