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

相关推荐
共享家95275 小时前
搭建 AI 聊天机器人:”我的人生我做主“
前端·javascript·css·python·pycharm·html·状态模式
Halo_tjn7 小时前
基于封装的专项 知识点
java·前端·python·算法
m0_748229999 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
C澒9 小时前
前端监控系统的最佳实践
前端·安全·运维开发
xiaoxue..10 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
hhy_smile10 小时前
Class in Python
java·前端·python
小邓吖10 小时前
自己做了一个工具网站
前端·分布式·后端·中间件·架构·golang
南风知我意95710 小时前
【前端面试2】基础面试(杂项)
前端·面试·职场和发展
LJianK111 小时前
BUG: Uncaught Error: [DecimalError] Invalid argument: .0
前端
No Silver Bullet11 小时前
Nginx 内存不足对Web 应用的影响分析
运维·前端·nginx