NodeJS

npm和yarn安装node-sass失败的完美解决方案

2017-7-2 1428字 8,876


由于某些不可描述的原因,利用npm进行安装模块的时候会发生xxx下载失败的情况node-sass尤其的频繁,或者说node-sass的二进制文件是接近百分百失败的,即使用yarn安装也依旧在这个点失败,以下是完整的解决方案。

全部的下载源指向cnpm的指令:

npm :

npm config set registry http://registry.npm.taobao.org

yarn :

yarn config set registry http://registry.npm.taobao.org

只指定node-sass的下载源:

npm:

npm config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
yarn:
yarn config set sass-binary-site http://npm.taobao.org/mirrors/node-sass

electron 镜像源:

yarn:

yarn config set ELECTRON_MIRROR https://npm.taobao.org/mirrors/electron/

  然后我可以正常使用npm或者yarn进行下载了~

最后,关于如何使用cnpm代替npm。。。。直接npm install cnpm -g就好了-。-~~~~ 然后就可以直接用cnpm install XXX等指令安装了。

npm & yarn代理设置

npm config set proxy http://127.0.0.1:10080
yarn config set proxy http://127.0.0.1:1080
npm config delete proxy
yarn config delete proxy

mac终端,当前有效

export http_proxy=http://proxyAddress:port

win CMD下

set HTTP_PROXY=http://127.0.0.1:10080
set HTTPS_PROXY=http://127.0.0.1:10080

power shell

设置代理
netsh winhttp set proxy http://127.0.0.1:10080
取消代理
netsh winhttp reset proxy http://127.0.0.1:10080
查看代理
netsh winhttp show proxy http://127.0.0.1:10080
版权声明:Shire 发表于 2017-7-2
转载请注明: npm和yarn安装node-sass失败的完美解决方案 | Shire

评论

该文章已经关闭评论