>nrm test
npm ---------- timeout (Fetch timeout over 5000 ms)
yarn --------- timeout (Fetch timeout over 5000 ms)
tencent ------ timeout (Fetch timeout over 5000 ms)
cnpm --------- timeout (Fetch timeout over 5000 ms)
taobao ------- timeout (Fetch timeout over 5000 ms)
npmMirror ---- timeout (Fetch timeout over 5000 ms)
huawei ------- timeout (Fetch timeout over 5000 ms)
1. 检查网络连接
# 检查网络连通性
ping registry.npmmirror.com
ping npmjs.com
2. 临时关闭防火墙和杀毒软件
Windows 防火墙或安全软件可能阻止了网络连接,暂时关闭后重试。
3. 配置代理(如果有网络限制)
如果你在公司或学校网络,可能需要配置代理:
# 设置代理(根据你的网络环境修改)
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
# 或者使用 socks 代理
npm config set proxy socks5://127.0.0.1:1080
4. 清除代理设置(如果之前配置过错误的代理)
# 清除代理配置
npm config delete proxy
npm config delete https-proxy
5. 手动设置淘宝源(绕过 nrm 测试)
# 直接设置淘宝源
npm config set registry https://registry.npmmirror.com/
# 验证设置
npm config get registry
# 测试下载(下载一个小包测试)
npm install lodash --verbose
6. 使用 cnpm(淘宝官方工具)
# 安装 cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com
# 使用 cnpm 代替 npm
cnpm install 包名
7. 检查 DNS 设置
有时 DNS 解析问题会导致连接超时,可以尝试:
# 刷新 DNS 缓存
ipconfig /flushdns
# 或者临时使用公共 DNS
# 在网络设置中将 DNS 改为 114.114.114.114 或 8.8.8.8
8. 使用 yarn 替代
# 安装 yarn
npm install -g yarn
# 设置 yarn 镜像源
yarn config set registry https://registry.npmmirror.com/
推荐操作步骤:
-
首先尝试直接设置淘宝源:
npm config set registry https://registry.npmmirror.com/ npm install lodash --verbose -
如果还是不行,尝试使用 cnpm:
npm install -g cnpm --registry=https://registry.npmmirror.com cnpm install lodash -
检查网络环境,确认是否有防火墙或代理限制。
通常国内网络环境下,淘宝源是最稳定的选择。