TimeoutError: The operation was aborted due to timeout at new DOMException

在安装前端项目依赖时,有时候会报超时错误:

TimeoutError: The operation was aborted due to timeout at new DOMException (node:internal/per_context/domexception:76:18) at Timeout._onTimeout (node:internal/abort_controller:154:9) at listOnTimeout (node:internal/timers:605:17) at process.processTimers (node:internal/timers:541:7) Progress: resolved 2005, reused 1917, downloaded 0, added 0 Downloading @iconify/json@2.2.481: 15.31 MB/89.70 MB

这是一个 npm 安装依赖时的网络超时错误 。错误显示下载 @iconify/json@2.2.481 这个包时超时了,只下载了 15.31 MB 中的一部分(总共 89.70 MB)。

解决方案:

1. 增加 npm 超时时间

复制代码
npm config set timeout 60000  # 设置为60秒

# 或者更长时间
npm config set timeout 120000  # 120秒

2. 切换 npm 镜像源(最推荐)

复制代码
# 使用淘宝镜像
npm config set registry https://registry.npmmirror.com

# 或者使用腾讯云镜像
npm config set registry https://mirrors.cloud.tencent.com/npm/

# 然后再重新安装
npm install

3. 使用 cnpm

复制代码
# 安装 cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com

# 使用 cnpm 安装
cnpm install

4. 只跳过失败的包,后续单独安装

复制代码
# 先安装其他包
npm install --ignore-scripts

# 单独安装失败的包
npm install @iconify/json --timeout=120000

5. 使用代理(如果你有代理)

复制代码
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

6. 清除缓存后重试

复制代码
npm cache clean --force
npm install --timeout=120000

7. 使用 yarn 替代

复制代码
# 安装 yarn
npm install -g yarn

# 配置 yarn 镜像
yarn config set registry https://registry.npmmirror.com

# 使用 yarn 安装
yarn install

推荐做法:

首选方案是切换镜像源(方案2),通常能解决大部分网络超时问题:

复制代码
npm config set registry https://registry.npmmirror.com
npm install

如果还是有问题,可以尝试增加超时时间并切换镜像源一起使用:

复制代码
npm config set registry https://registry.npmmirror.com
npm config set timeout 120000
npm install

这个包 @iconify/json 体积较大(约90MB),在网络不稳定时确实容易超时。

内容来自 DeepSeek。

相关推荐
冬奇Lab13 小时前
DeepSeek Harness 系列(06):System Prompt 组装——动态提示词的工程实现
人工智能·deepseek
三声三视15 小时前
75 条文章索引被一条 add 清成 1 条,退出码还是 0:tri-article 的 index.py 我读了 205 行
人工智能·ai·skill·tri-skills·tri-article
蔡俊锋16 小时前
DeepSeek 语音对话灰度上线:四种音色背后的端侧 AI 交互架构与商业逻辑
架构·大模型·语音交互·deepseek·端侧ai
牛油果子哥q16 小时前
生产级AI项目上线全流程:Docker容器化、服务编排、监控告警、日志收集、容灾降级、线上运维闭环
人工智能·ai
星辰徐哥16 小时前
本地视频预览别只自己看:把Remotion动效项目发给客户远程验收
docker·ai·node.js·html·音视频·react·remotion
大模型真好玩17 小时前
DeepSeek Harness 入门很简单(四)——DeepSeek Harness接入插件
人工智能·agent·deepseek
JudithHuang18 小时前
Claude 桌面端入门:Claude Desktop + cc-switch + DeepSeek
claude·deepseek
HYDtomako18 小时前
Agent checkpoint设计
ai·agent·checkpoint·claude code
七灵微20 小时前
【AI】代码实战- 基于时间序列的轴承检测1
人工智能·机器学习·ai·pandas·matplotlib
RSABLOCKCHAIN20 小时前
读懂AI-Agent项目Career-ops项目的底层原理
ai