npm i报错request to https://registry.npmjs.org/xxx failed, reason: connect ETIMEDOUT 104.16.25.34:443
·
如果执行npm install 时,出现以下错误:
是因为访问https://registry.npmjs.org
这个地址需要翻墙才能访问,所以在国内经常会出现连接超时等问题。为了解决这个问题,可以将npm的源设置为国内的镜像例如淘宝镜像。
以下是设置淘宝镜像的方法:
方法一:
//将npm设置为淘宝镜像
npm config set registry http://registry.npmmirror.com
//输入上述命令后,npm就会将镜像源设置为淘宝镜像,可以一下命令来验证即查看npm镜像设置
npm config get registry
//如果输出结果为 https://registry http://registry.npmmirror.com/,则说明已经成功设置镜像源
//尝试重新执行,应该就能够成功安装了
npm install
//另外,如果不想全局设置 npm 的镜像源,也可以在执行 npm install 命令时指定镜像源,例如:
npm install --registry=https://registry.npmmirror.com
方法二:
在终端cmd
// 执行 nrm ls 查看所有可用的 registry
C:\Users\测试>nrm ls
npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.npmmirror.com/
npmMirror ---- https://skimdb.npmjs.com/registry/
//执行nrm use taobao 切换到指定的 registry
C:\Users\测试>nrm use taobao
SUCCESS The registry has been changed to 'taobao'.
C:\Users\测试>nrm ls
npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
* taobao ------- https://registry.npmmirror.com/
npmMirror ---- https://skimdb.npmjs.com/registry/
然后再次运行npm install
更多推荐
已为社区贡献6条内容
所有评论(0)