1. 问题描述

npm使用淘宝镜像安装报错

npm ERR! code CERT_HAS_EXPIRED

npm ERR! errno CERT_HAS_EXPIRED

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

npm 报错 request to https://registry.npm.taobao.org/three failed, reason: certificate has expired_nodejs

2. 错误原因

错误提示已经告诉原因是淘宝镜像过期了!

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

2024年1 月 22 日,淘宝原镜像域名(registry.npm.taobao.org)的 HTTPS 证书正式到期,导致旧的 npm 淘宝镜像在使用时出错了。

3. 解决方案

npm 报错 request to https://registry.npm.taobao.org/three failed, reason: certificate has expired_npm_02

3. 1 清空缓存

npm cache clean --force

3.2 查看当前的npm镜像设置

npm config get registry

3.3 切换新源

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

3.4 查看新源是否设置成功

npm config get registry

3.5 可以正常安装需要的工具了

npm insatll