您的位置:首页 > Web前端 > AngularJS

MAC上安装angular时碰到的一些问题

2020-05-15 23:16 176 查看

想在mac上安装angular,中途碰到一些问题,现已解决。特此分享,供参考。

我一开始用如下命令直接安装:

npm install -g @angular/cli

安装过程中碰到如下的报错1:

xxxdeMBP:~ xxx$ npm install -g @angular/clinpm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning undefined: network timeout at: https://registry.npmjs.org/@angular-devkit%2fcore
npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
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!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yangmuxue/.npm/_logs/2020-05-15T14_23_03_431Z-debug.log

报错1的解决方法:
由于报错显示路径’/usr/local/lib/node_modules’存在权限问题,于是我用以下命令查看了这个文件的拥有者:

xxxxdeMBP:_logs xxxx$ ls -la /usr/local/lib/node_modules
total 0
drwxr-xr-x   3 root  wheel   96  5 15 22:18 .
drwxr-xr-x   5 root  wheel  160  5 15 22:18 ..
drwxr-xr-x  24 root  wheel  768  4 28 19:15 npm

这个文件的拥有者是root,所以我当前的身份不能进行修改。于是我修改了这些文件的拥有者。

sudo chown -R xxxx(新的拥有者): /usr/local/lib/node_modules

再次查看文件权限:

xxxxdeMBP:_logs xxxx$ ls -la /usr/local/lib/node_modules
total 0
drwxr-xr-x   3 xxxx  wheel   96  5 15 22:18 .
drwxr-xr-x   5 root       wheel  160  5 15 22:18 ..
drwxr-xr-x  24 xxxx  wheel  768  4 28 19:15 npm

虽然仍然有一个文件的拥有者是root,当我始终改不掉。于是尝试性地重新安装,可又遇到了报错2:

xxxxdeMBP:~ xxxx$ npm install -g @angular/clinpm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/@angular/cli/bin/ng
npm ERR! dest /usr/local/bin/ng
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@angular/cli/bin/ng' -> '/usr/local/bin/ng'
npm ERR!  [OperationalError: EACCES: permission denied, symlink '../lib/node_modules/@angular/cli/bin/ng' -> '/usr/local/bin/ng'] {
npm ERR!   cause: [Error: EACCES: permission denied, symlink '../lib/node_modules/@angular/cli/bin/ng' -> '/usr/local/bin/ng'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'symlink',
npm ERR!     path: '../lib/node_modules/@angular/cli/bin/ng',
npm ERR!     dest: '/usr/local/bin/ng'
npm ERR!   },
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'symlink',
npm ERR!   path: '../lib/node_modules/@angular/cli/bin/ng',
npm ERR!   dest: '/usr/local/bin/ng'
npm ERR! }
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/yangmuxue/.npm/_logs/2020-05-15T14_44_36_347Z-debug.log

报错2的解决方法:用如下命令重新安装:

sudo npm install -g @angular/cli

我的安装到此就成功了。以上分享供小伙伴们参考!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: