上学的时候在美国装了npm,回国之后出现各种问题。后来发现时被block了。试过痛过修改一些环境变量来使用镜像,但是后来发现最好用的方法是这个:
万能的解决npm无法安装好的方法!!!!!!!!!!!!!!
npm install -g cnpm --registry=https://registry.npm.taobao.org
$ cnpm -v
cnpm好像是阿里弄的一个东西,安装之后指令和npm一样,只用把指令里面的npm改成cnpm就好了。
cnpm可以一次替换也可以永久替换
一次替换
npm install --registry=https://registry.npm.taobao.org
永久替换
npm config set registry https://registry.npm.taobao.org
npm相关的东西里面又时候会用到xcode
接下来解决如果电脑里没有xcode或clt
xcode非常大,安装需要很长时间。如果一发现xcode出错,就直接卸载重装,代价其实很大。有时候可能只是其中某个地方版本不兼容或者参数没有设置好,导致不能正常使用xcode而已。
这时候可以先在终端输入如下命令查看当前xcode和CLT(Command Line Tools)版本
brew config
如果MAC下npm install报错No receipt for ‘com.apple.pkg.CLTools_Executables’ found at ‘/’.
并且上一条指令输入发现clt是已经安装了。那么就删除已经安装的CommandLineTools
sudo rm -rf $(xcode-select -p)
然后重新安装
sudo xcode-select --install
同意条款选择同意,会提示系统更新一并同意。
另外,如果更新失败可以登录 https://developer.apple.com/download/more/,需要Apple ID登录,下载Command Line Tooles for Xcode 12 dmg软件包,然后安装。
最后一个报错提示
在执行npm install时,如果出现报错
RunScriptError: post install error, please remove node_modules before
retry!
或者cnpm install报错:
RunScriptError: post install error, please remove
node_modules before retry!
解决:
(1)先到项目文件下重命名或者删除node_modules这个文件
rm -rf node_modules/
(2)安装gulp-sass
$ cnpm install gulp-sass --save-dev
(3)安装成功后,再cnpm install
$ cnpm install
亲测成功
如果在npm安装的过程中还有遇到别的问题,也可以私信我或者评论留言。大家一起交流