npm install时报错 reason: connect ETIMEDOUT

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

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的镜像源设置为国内的即可(任选一种):

# 更换成淘宝镜像源
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

相关推荐

  1. 【MySQL】创建用户时报

    2024-07-19 05:20:02       50 阅读
  2. docker commit镜像时报

    2024-07-19 05:20:02       32 阅读
  3. Vue中使用Element-ui时报

    2024-07-19 05:20:02       41 阅读
  4. Nodejs引入模块运行时报

    2024-07-19 05:20:02       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 05:20:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 05:20:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 05:20:02       58 阅读
  4. Python语言-面向对象

    2024-07-19 05:20:02       69 阅读

热门阅读

  1. npm相关指令

    2024-07-19 05:20:02       22 阅读
  2. 【Unity】RPG2D龙城纷争(十四)存档系统

    2024-07-19 05:20:02       19 阅读
  3. 点的距离(C++)

    2024-07-19 05:20:02       19 阅读
  4. itextpdf 使用demo

    2024-07-19 05:20:02       26 阅读
  5. chatglm2-6b-prompt尝试

    2024-07-19 05:20:02       20 阅读
  6. IKM 外企常用

    2024-07-19 05:20:02       21 阅读
  7. Linux源码阅读笔记13-进程通信组件上

    2024-07-19 05:20:02       20 阅读
  8. 分布式唯一id的7种方案

    2024-07-19 05:20:02       24 阅读
  9. 编程中的智慧之设计模式三

    2024-07-19 05:20:02       21 阅读
  10. 解决用PicGo为typora配置github图床失败的问题

    2024-07-19 05:20:02       19 阅读
  11. shape_trans 变换区域的形状

    2024-07-19 05:20:02       22 阅读