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

相关推荐
程序员海军4 小时前
用了两年多 GPT,我最近开始换模型了,还折腾了个求职避坑 Agent
前端·人工智能·后端
zttbee4 小时前
echarts图表tooltip色块失效
前端·javascript·echarts
excel6 小时前
IndexNow:让搜索引擎更快发现网站更新的主动通知协议
前端·后端·架构
Json____6 小时前
用 FastAPI + Vue3 打造一套完整的在线考试系统:从组卷到阅卷的业务闭环实践
后端·node.js·fastapi·it学习·wwwoop.com
子兮曰6 小时前
CSS 复现 23 种设计风格:从拟物到液态玻璃的成本阶梯与兜底写法【实战】
前端·css·视觉设计
虚无境6 小时前
如何用AI帮我写出实用的插件
前端·javascript·ai编程
柳杉7 小时前
从数字化到数智化:3D 可视化大屏的下一个五年
前端·ai编程·数据可视化
风骏时光牛马8 小时前
从零到实战:AI全栈学习进阶路线
前端
FRing038 小时前
JavaScript入门到精通二十六(变量提升、函数剩余参数、展开运算符、ES6箭头函数)
开发语言·前端·javascript·es6·箭头函数
用户360055579008 小时前
Kestrel_VLLM - 15 · decode 优化四连击:19ms → 8ms
前端