1. 问题
今天在安装ng-alain
依赖时出现以下错误
2. 解决办法
- 先尝试将
npm
升级到最新版
$ npm install npm -g
# 检查版本
$ npm -v
6.14.5
- 运行以下命令删除当前路径下的
node_modules
目录
$ rm node_modules
# Are you sure you want to continue?
# [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y")
# 键入 Y 或 A
运行以下命令强制删除npm
缓存,然后重新安装
$ npm cache clean --force
# 重新安装
$ npm install
又出现了新的错误npm ERR! Error: EPERM: operation not permitted
- 在Google上找了下解决方案,发现删除目录
C:\Users\{yourusername}\.npmrc
后,重新安装可以成功。
$ npm install
3. 终极方案(慎用)
注意:
cnpm
虽然可以顺利安装,但会引发一些未知的错误,请谨慎使用。
如果以上方法都不可行,可安装cnpm
$ npm install -g cnpm
然后在目录中执行
$ cnpm install