npm install 失败解决方案
npm install 安装过程中,报如下错误:
bower install 报错fatal: unable to access 'https://github.com/angular/bower-angular-touch.git/'
说明与GITHUB通信失败,查看npm配置:
git config --global -l
确认无设置任何代理:
npm config get proxy
npm config get https-proxy
如果返回值不为null,继续执行:
npm config set proxy null
npm config set https-proxy null
另外可设置DNS为8.8.8.8 增加成功几率
vi /etc/resolve.conf
nameserver 8.8.8.8
方法一:(单个URL替换)
开始我一个一个解决,把https换成了git
例子如下:
git config --global url."git://github.com/angular/bower-angular-touch.git/".insteadOf https://github.com/angular/bower-angular-touch.git/
然后再执行 npm install ,但是类似的错误太多了,一个一个替换太麻烦,来个批量的。
git config --global url."git://".insteadOf https://
然后执行 npm install(一次不行多试几次)
方法二:(换源)
查看当前源:
npm config get registry
npm使用国内镜像加速的几种方法
在使用npm过程中经常会遇到无法下载包的问题,本人在这里整理了几个npm使用国内镜像加速的方法,希望对大家有所帮助。
原始配置 npm config set registry http://registry.npmjs.org/ , 在发布npm包时,请使用原始配置
一、修改成淘宝镜像源
命令
npm config set registry https://registry.npm.taobao.org
验证命令
npm config get registry
如果返回https://registry.npm.taobao.org,说明镜像配置成功。
二、修改成华为云镜像源
命令
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
验证命令
npm config get registry
如果返回https://mirrors.huaweicloud.com/repository/npm/,说明镜像配置成功。
三、通过使用淘宝cnpm安装
安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
使用cnpm
cnpm install xxx
以上 临时使用方式
npm install --registry=https://registry.npm.taobao.org
方法三:CDN加速
git config --global url."https://ghproxy.com/https://github.com".insteadOf "https://github.com"
或
git config --global url."https://hub.fastgit.org/".insteadOf "https://github.com/"
注意:以上两点都是对 https 协议进行代理设置,也就是仅对 git clone https://www.github.com/xxxx/xxxx.git 这种命令有效。对于 SSH 协议,也就是 git clone git@github.com:xxxxxx/xxxxxx.git 这种,依旧是无效的。
配置参数修改
git config --global --edit
总结:
一般情况下 使用 cnpm 和 npm 结合的方式,例如先用 cnpm下载下来npm下载失败的模块,然后再用npm 下载剩余的模块,例如 bower
cnpm install bower@1.8.8 然后 npm install
注意版本对应
posted on 2021-08-23 13:19 TrustNature 阅读(5283) 评论(0) 收藏 举报
浙公网安备 33010602011771号