npm install时报错 reason: connect ETIMEDOUT

在VS code中导入新项目,执行npm install时报错:

bash 复制代码
npm warn old lockfile Could not fetch metadata for @antv/coord@0.1.0 FetchError: request to https://registry.npmjs.org/@antv%2fcoord failed, reason: connect ETIMEDOUT 150.242.56.251:443
npm warn old lockfile     at ClientRequest.<anonymous> (D:\softFile\Node.js\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm warn old lockfile     at ClientRequest.emit (node:events:519:28)
npm warn old lockfile     at _destroy (node:_http_client:880:13)
npm warn old lockfile     at onSocketNT (node:_http_client:900:5)
npm warn old lockfile     at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
npm warn old lockfile   code: 'ETIMEDOUT',
npm warn old lockfile   errno: 'ETIMEDOUT',
npm warn old lockfile   syscall: 'connect',
npm warn old lockfile   address: '150.242.56.251',
npm warn old lockfile   port: 443,
npm warn old lockfile   type: 'system'
npm warn old lockfile }

原因: 由于访问国内访问npm的资源库地址(https://registry.npmjs.org)连接超时导致。

解决办法:

1)将npm的镜像源设置为国内的即可(任选一种):

bash 复制代码
# 更换成淘宝镜像源
npm config set registry https://registry.npm.taobao.org
 
# 更换成阿里镜像源
npm config set registry https://npm.aliyun.com/
 
# 更换成华为镜像源
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
 
# 更换成腾讯镜像源
npm config set registry http://mirrors.cloud.tencent.com/npm/

2)设置完成后,重新执行npm即可。

**扩展:**通过下面命令可查看当前的镜像源:

npm config get registry

相关推荐
魔云连洲2 分钟前
深入解析:Vue与React的异步批处理更新机制
前端·vue.js·react.js
mCell32 分钟前
JavaScript 的多线程能力:Worker
前端·javascript·浏览器
超级无敌攻城狮2 小时前
3 分钟学会!波浪文字动画超详细教程,从 0 到 1 实现「思考中 / 加载中」高级效果
前端
excel3 小时前
用 TensorFlow.js Node 实现猫图像识别(教学版逐步分解)
前端
gnip3 小时前
JavaScript事件流
前端·javascript
赵得C3 小时前
【前端技巧】Element Table 列标题如何优雅添加 Tooltip 提示?
前端·elementui·vue·table组件
wow_DG4 小时前
【Vue2 ✨】Vue2 入门之旅 · 进阶篇(一):响应式原理
前端·javascript·vue.js
weixin_456904274 小时前
UserManagement.vue和Profile.vue详细解释
前端·javascript·vue.js
资深前端之路4 小时前
react 面试题 react 有什么特点?
前端·react.js·面试·前端框架
aaaweiaaaaaa4 小时前
HTML和CSS学习
前端·css·学习·html