Mac无法安装Angular-CLI

时间:2019-05-31 15:04:41

标签: node.js macos ionic-framework 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,然后输入“是”。然后我得到这些错误。

[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.

1 个答案:

答案 0 :(得分:0)

如果这里有人遇到与我相同的问题,基本上我所做的就是跑

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

在我的终端中,然后重新启动计算机。完成之后,我实际上只是创建了一个新项目,然后从那里添加了所有内容(包括Angular CLI)