2019-11-07 更新
我知道为啥报错了,自我好好反省一下!!!
所以,Mac的终端,不能用简写的命令,哭泣。。。
不过下面的,就可以看作安装卸载@angular/cli了
在全局安装angular-cli且成功之后,查看ng v ,报错了Error: ENOENT: no such file or directory, scandir '/Users/echo_hx/node_modules'。。。。
我去查了日志,如下:
[error] Error: ENOENT: no such file or directory, scandir '/Users/echo_hx/node_modules'
at Object.readdirSync (fs.js:854:3)
at VersionCommand.run (/usr/local/lib/node_modules/@angular/cli/commands/version-impl.js:50:41)
at VersionCommand.validateAndRun (/usr/local/lib/node_modules/@angular/cli/models/command.js:134:39)
at async Object.runCommand (/usr/local/lib/node_modules/@angular/cli/models/command-runner.js:186:24)
at async default_1 (/usr/local/lib/node_modules/@angular/cli/lib/cli/index.js:54:31)
我百度了,也没找到实用的方法。它们总是node-sass安装问题,头秃。于是,我只能卸载重装了,一般npm也会产生不可预料的未知错误,所以也要安装cnpm,用yarn也行。
1.重装angular-cli
npm uninstall -g @angular/cli
再清一下缓存
npm cache clean --force
若清空缓存时出现错误,执行以下命令,要么没权限啥的,用sudo
npm cache clear --force && npm install --no-shrinkwrap --update-binary
2.设置淘宝代理,以安装cnpm。cnpm可代替npm,命令格式相同。
npm config rm proxy
npm config rm https-proxy
sudo npm install cnpm -g --registry=https://registry.npm.taobao.org
3.然后安装Angular-cli
cnpm install -g @angular/cli@latest
最后,ng v 查看版本
OK,,,完美……^ _ ^
参考文章:全局安装 Angular CLI