npm,yarn如何查看源和换源

npm, yarn查看源和换源:

1
npm config get registry 

设置npm镜像源为淘宝镜像

1
npm config set registry https://registry.npm.taobao.org/ 

查看yarn当前镜像源

1
yarn config get registry

设置yarn镜像源为淘宝镜像

1
yarn config set registry https://registry.npm.taobao.org/

镜像源地址部分如下:

1
2
3
4
5
6
7
npm --- https://registry.npmjs.org/
cnpm --- https://r.cnpmjs.org/
taobao --- https://registry.npm.taobao.org/
nj --- https://registry.nodejitsu.com/
rednpm --- https://registry.mirror.cqupt.edu.cn/
npmMirror --- https://skimdb.npmjs.com/registry/
deunpm --- http://registry.enpmjs.org/

如yarn 或者npm install的时候报错如下:

1
2
3
4
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.npmjs.org/eslint-plugin-react: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:1087".

问题是代理连接不上,可通过一下命令查看代理情况:

1
yarn config list 

修改代理为正确的即可,也可以使用淘宝镜像源解决

1
2
yarn config set proxy  http://username:password@server:port
yarn config set https-proxy http://username:password@server:port