前言

    在使用npm工具安装软件的时候,常常由于国内网络环境的缘故,导致访问国外资源站点速度特别慢,甚至网络异常。所以通常,我们会更换npm的资源地址为国内的镜像站点

常见的npm资源地址访问网络异常提示如下:

1
2
3
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/hexo: getaddrinfo ENOTFOUND registry.yarnpkg.com".
info If you think this is a bug, please open a bug report with the information provided in "/Users/mac/.config/yarn/global/yarn-error.log".

更换资源地址

1,国内一般使用taobao的镜像站点作为资源地址,通过下面的命令可以进行更换:

1
2
npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist

2,验证配置,查看配置的registry和disturl地址

1
2
npm get registry
npm get disturl

3,如果需要还原为默认的地址,执行下面的命令

1
2
npm config delete registry
npm config delete disturl