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。

相关推荐
hoLzwEge19 小时前
前端项目的基石:深入解读 package.json 的作用与核心配置
前端·前端框架
头茬韭菜19 小时前
最小命令式Store与分层持久化——Agent的“记忆宫殿“
ai
不简说20 小时前
拖拽DIY表格插件来了!sv-print 七月更新:这次真的能自己拼表格了
前端·javascript·前端框架
dozenyaoyida20 小时前
AI与大模型新闻日报 | 2026-07-11
人工智能·ai·大模型·新闻
猿的天空1 天前
GPT-5.6拆成三段,智能变成了可选购配置
人工智能·gpt·计算机·ai·程序员·大模型·智能体
m0_547486661 天前
《DeepSeek生成式人工智能教与学》全套PPT课件
人工智能·deepseek
曦尧1 天前
Awesome LLM Apps:一个 100+ 可运行 AI Agent / RAG 模板库的价值与边界
ai·自动化
俊哥V1 天前
每日 AI 研究简报 · 2026-07-12
人工智能·ai
离离原上草771 天前
开源!我用 Python 造了个 AI 视频生成框架,输入一句话自动出片
ai·开源软件
星释1 天前
鸿蒙智能体开发实战:41.智能体上架审核规范与合规指南
华为·ai·harmonyos·鸿蒙