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

相关推荐
用户91743965393 分钟前
Magnitude:强!一款基于 Al 视觉的 Web 自动化框架
运维·前端·自动化
军军君0139 分钟前
Three.js基础功能学习四:摄像机与阴影
开发语言·前端·javascript·3d·typescript·three·三维
lambo mercy1 小时前
python入门
前端·数据库·python
GIS之路2 小时前
GDAL 实现矢量数据读写
前端
05大叔2 小时前
MybatisPlus
java·服务器·前端
slongzhang_2 小时前
edge/Chrome浏览器闪屏/花屏
前端·chrome·edge
想要一辆洒水车2 小时前
npm包开发及私有仓库配置使用
前端
低代码布道师2 小时前
互联网医院18:前端进阶——CSS“父相子绝”打造专业级卡片交互
前端·css·低代码·小程序·云开发
luckyCover2 小时前
Vue源码分析 - 从入口到构造函数的整体流程
前端·vue.js
听风说图2 小时前
AI设计类产品分析:Lovart
前端