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。

相关推荐
cpolar技术支持6 小时前
容器数是 6 个、6 个、还是 6 个,可服务早被换掉了:用一个 5.5MB 的 Go 单文件把机器每周的变化记下来,再给它套一层别人看不懂的入口
python·docker·ai·cpolar
黑土豆6 小时前
网页框一下就能截图Region-snap:我把这套功能封装成了 npm 包,支持 Vue 和 React
前端·javascript·npm
万俟淋曦7 小时前
[ROS 系列学习教程] 建模与仿真 - 使用 ros_control 控制六轴串联机械臂
人工智能·ai·机器人·ros·机械臂·robotics·具身智能
效率工作实验室8 小时前
企业级AI Agent平台选型指南:主流厂商能力对比与落地场景解析
ai·企业级ai·agent平台选型·agent平台能力对比·企业智能体落地场景
土豆125017 小时前
dsh-orchestrator 介绍与使用实践:让你的 AI 从「一个人硬扛」到「带团队干活
llm·ai编程·deepseek
进击的雷神19 小时前
不预测数字,而是重演未来:多智能体仿真引擎 MiroFish 上手体验
ai·开源·mirofish
dozenyaoyida19 小时前
AI与大模型新闻日报 | 2026-11-08
人工智能·搜索引擎·ai·大模型·新闻
Solange__1 天前
Blender 3D模型优化:普通复制、共享网格、实例、合并怎么选?
人工智能·3d·ai·自然语言处理·编辑器·blender·材质
菩提小狗1 天前
每日极客日报 · 2026年11月13日
ai·开源·极客日报·it热点·技术资讯