关于npm install报错ERR code ETIMEDOUT的问题及解决
作者:前端 贾公子
这篇文章主要介绍了关于npm install报错ERR code ETIMEDOUT的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
npm install报错ERR code ETIMEDOUT
//1.查看npm镜像设置 npm config get registry //2.将npm设置为淘宝镜像 npm config set registry https://registry.npm.taobao.org //3.再次查看npm镜像设置 npm config get registry //4.重新install npm install
要查看npm源,可以使用以下命令:
1. 查看当前的npm源
npm config get registry
2. 查看所有可用的npm源
npm config ls -l
3. 切换npm源
npm config set registry
其中,``是你要切换的npm源的URL。
例如,要查看当前的npm源,可以运行以下命令:
npm config get registry
输出类似于`https://registry.npmjs.org/`的URL,表示当前的npm源是官方的npm源。
要查看所有可用的npm源,可以运行以下命令:
npm config ls -l
这会列出所有的npm配置,包括当前的npm源。
要切换npm源,可以运行以下命令:
npm config set registry
例如,要切换到淘宝的npm源,可以运行以下命令:
npm config set registry https://registry.npm.taobao.org/
npm安装报错 npm ERR! request to https://registry.npm.taobao.org/ failed, reason: certificate has expired
错误原因:
- 2024年1 月 22 日,淘宝原镜像域名(registry.npm.taobao.org)的 HTTPS 证书正式到期,导致旧的 npm 淘宝镜像在使用时出错了。
- 早在 2021 年,淘宝就发文称,npm 淘宝镜像已经从 registry.npm.taobao.org 切换到了 registry.npmmirror.com。旧域名也将于 2022 年 5 月 31 日停止服务(不过,直到 HTTPS 证书到期才真正不能用了)。
解决方案:
// 1. 清空缓存 npm cache clean --force // 2. 切换新源 npm config set registry https://registry.npmmirror.com // 3. 查看源是否设置成功 npm config get registry // 4. 可以正常安装需要的工具了 npm insatll xxx )
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。