You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

npm install报ERR_SOCKET_TIMEOUT错误,请求协助排查

解决npm install时请求npmmirror资源的Socket超时问题

问题详情

运行环境:Ubuntu 22.04.4,Node.js v14.4.0,npm v7.14.0
执行npm install时触发超时错误:

npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! request to https://registry.npmmirror.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz failed, reason: Socket timeout

已尝试卸载重装Node.js+npm、清理npm缓存,问题未解决。

可行解决方案

1. 延长npm超时阈值

旧版npm默认超时时间较短,针对网络波动或大资源包容易触发超时,执行以下命令调整:

npm config set fetch-timeout 600000
npm config set timeout 600000

设置完成后重新运行npm install。

2. 更换镜像源

当前使用的npmmirror节点可能存在访问瓶颈,切换到其他稳定镜像测试:

# 切换至npm官方源
npm config set registry https://registry.npmjs.org/
# 或切换至npmmirror备用节点
npm config set registry https://npmmirror.com/mirrors/npm/

切换后执行npm cache clean --force清理缓存,再重新执行安装命令。

3. 排查服务器网络链路

测试服务器与镜像节点的连通性:

# 检测延迟
ping registry.npmmirror.com
# 测试资源下载速度
curl -O https://registry.npmmirror.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz -w "Total time: %{time_total}s\n"

如果延迟过高或下载超时,说明网络链路存在问题,需联系服务商调整线路,或使用合规代理。

4. 升级Node.js与npm版本

当前使用的Node.js v14.4.0和npm v7.14.0均为老旧版本,存在网络请求相关的兼容性问题,建议升级至LTS版本:

# 安装nvm(版本管理工具)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
# 安装并切换至Node.js v20 LTS
nvm install 20
nvm use 20

升级后重新运行npm install。

5. 手动导入依赖包

若上述方法无效,可手动下载出错的依赖包并放入npm缓存:

  1. 下载acorn-import-assertions-1.8.0.tgz包
  2. 找到npm缓存目录(当前环境为/www/server/nodejs/v14.4.0/cache/),按照debug日志中的缓存路径结构放置该包
  3. 重新执行npm install

内容的提问来源于stack exchange,提问作者ianasystems

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 16:42:43