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
方法一:(單個)
開始我一個一個解決,把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 config set registry http://registry.npmjs.org/
使用淘寶源,再執行:
npm install --registry=https://registry.npm.taobao.org --unsafe-perm=true --allow-root
使用 cnpmjs 源:
npm config set registry http://registry.cnpmjs.org
方法四:(cnpm)
直接使用淘寶的cnpm
npm install -g cnpm --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
這種,依舊是無效的。