npm 及 yarn 代理设置及更换为国内下载源

发布于 2024-01-24 17:03:21

由于有时候网络的原因,会导致 npm 、yarn 下载遇到各种各样的问题。而且我们正好会使用科学上网方法。那么我们就可以为 npm 、yarn 设置代理。让它们通过代理的方式的得到更优的下载网络,从而解决疑难杂症。

设置proxy:

yarn config set https-proxy http://127.0.0.1:7890
yarn config set proxy http://127.0.0.1:7890

npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890

取消代理:

yarn config delete proxy
yarn config delete https-proxy

npm config delete proxy
npm config delete https-proxy

修改源:

//淘宝
yarn config set registry http://registry.npm.taobao.org/
//淘宝2
yarn config set registry https://registry.npmmirror.com/
//官方
yarn config set registry https://registry.yarnpkg.com

//淘宝
npm config set registry http://registry.npm.taobao.org/
//淘宝2
npm config set registry https://registry.npmmirror.com/
//官方
npm config set registry https://registry.npmjs.org/

查看当前设置的源:

// yarn 默认:https://registry.yarnpkg.com
yarn config get registry 
npm get registry

例如在TvT.js项目中遇到:

ERR! network request to https://registry.npmjs.org/@alienkitty%2fspace.js failed, reason: connect ETIMEDOUT 104.16.27.34:443

或者

ERR! No versions available for @alienkitty/space.js
npm config set registry https://registry.npmmirror.com/

或者

error Received malformed response from registry for "@alienkitty%2fspace.js". The registry may be down.

需要使用:
官方的源,且使用翻墙proxy代理来安装依赖

3 条评论

发布
问题