npm 淘宝镜像到期了,尽快切换~(npm使用淘宝镜像安装时报错)

★npm使用淘宝镜像安装时突然报错了错误及解决方案如下。

一、错误内容:

npm ERR! request to https://registry.npm.taobao.org/cnpm failed, reason: certificate has expired

npm ERR! code CERT_HAS_EXPIRED

npm ERR! errno CERT_HAS_EXPIRED

npm ERR! request to https://registry.npm.taobao.org/cnpm failed, reason: certificate has expired

npm ERR! A complete log of this run can be found in: D:\nodejs\node_cache\_logs\2024-01-23T11_00_28_143Z-debug-0.log

二、解决方案:

方法①:可以解决但建议用第二种方法

// 1. 清空缓存

npm cache clean --force

// 2. 关闭SSL验证

npm config set strict-ssl false

// 3. 安装

到这里就可以正常使用npm命令安装需要的工具了。如( npm install -g cnpm )

方法②:将npm淘宝镜像切换至淘宝的新镜像域名

// 1. 清空缓存

npm cache clean --force

// 2. 切换新源

npm config set registry https://registry.npmmirror.com

// 3. 查看源是否设置成功

npm config get registry

// 4. 安装

到这里就可以正常使用npm命令安装需要的工具了。如( npm install -g cnpm )

三、出错原因:

​ 2024年1 月 22 日,淘宝原镜像域名(registry.npm.taobao.org)的 HTTPS 证书正式到期。这就导致旧的 npm 淘宝镜像在使用时出错了: ​ 众所周知,npm 官方镜像(registry.npmjs.org)在国内访问很慢,很多人都会选择切换到国内的 淘宝npm镜像。

​ 其实,早在 2021 年,淘宝就发文称,npm 淘宝镜像已经从 registry.npm.taobao.org 切换到了 registry.npmmirror.com。旧域名也将于 2022 年 5 月 31 日停止服务(不过,直到昨天 HTTPS 证书到期才真正不能用了)。

​ 淘宝文件内容如下:

所以,遇到上述问题,或者还在使用旧的 npm 淘宝镜像,直接将 npm 源切换到新的源即可:即本文中的解决方法②。

推荐文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: