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

ArchLinux下npm安装包冻结并报ETIMEDOUT错误求助

解决npm安装依赖ETIMEDOUT冻结问题(ArchLinux + Node.js 21.6.0 + npm 10.3.0)

问题描述

在ArchLinux系统中使用npm 10.3.0与Node.js 21.6.0安装依赖包时,进程出现冻结情况。在另一个项目中等待约10分钟后,出现以下错误:

Using version ^1.28 for laravel/breeze

   INFO  Installing and building Node dependencies.  

npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/@tailwindcss%2fforms failed, reason: 
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

实际网络速度为150Mbps(经fast.com测试),相关问题截图:

npm安装时的冻结情况

Laravel启动项目时的错误截图:

Laravel启动时的错误

npm日志文件/home/abdullajonov/.npm/_logs/2024-01-19T16_28_58_849Z-debug-0.log内容过多无法全部粘贴。

解决步骤

1. 切换npm镜像源

默认的npm官方源在国内访问可能不稳定,切换到国内镜像源:

  • 设置淘宝镜像源:
    npm config set registry https://registry.npmmirror.com/
    
  • 验证源是否切换成功:
    npm config get registry
    
  • 也可以在安装时临时指定源:
    npm install --registry=https://registry.npmmirror.com/
    

2. 清理异常代理设置

即使网络正常,残留的代理配置可能导致请求超时:

  • 查看当前代理配置:
    npm config get proxy
    npm config get https-proxy
    
  • 若存在异常代理,执行以下命令清空:
    npm config delete proxy
    npm config delete https-proxy
    
  • 同时检查系统环境变量中的代理,执行以下命令查看,若有设置可临时取消:
    echo $HTTP_PROXY
    echo $HTTPS_PROXY
    

3. 调整npm超时与重试参数

增加超时时间和重试次数,避免因网络波动导致超时:

npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 60000

4. 清理npm缓存

缓存损坏也可能导致安装异常:

npm cache clean --force

清理完成后重新执行依赖安装命令。

5. 切换到稳定版Node.js

Node.js 21.x为开发版,可能存在兼容性问题,建议切换到LTS稳定版(如20.x):

  • 安装nvm版本管理器:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    
  • 安装20.x稳定版:
    nvm install 20
    
  • 切换到该版本:
    nvm use 20
    
  • 之后再尝试执行npm安装命令。

6. 检查系统防火墙与网络拦截

临时关闭防火墙或网络拦截工具,测试是否是拦截导致的问题:

  • 若使用firewalld:
    sudo systemctl stop firewalld
    
  • 若使用ufw:
    sudo ufw disable
    
  • 同时关闭VPN、代理软件等,再重新运行npm安装。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 20:53:11