npm “https://registry.npm.taobao.org/...: certificate has expired“(证书已过期) 解决方法

本文讲述了在使用npm下载依赖时遇到的淘宝镜像证书过期问题,提供了解决方案,即切换到npmmirror.com或其他官方和云服务商提供的NPM镜像地址.

今天在使用npm下载依赖的时候出现淘宝镜像证书过期问题

error An unexpected error occurred: "https://registry.npm.taobao.org/axios: certificate has expired"

原因: 淘宝镜像原地址2024年1月22日已过期

解决: 解决方法就是切换淘宝最新镜像地址,执行完成之后就可以正常下载依赖了

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

其他镜像源

npm 官方原始镜像网址是:https://registry.npmjs.org/
淘宝最新 NPM 镜像:https://registry.npmmirror.com
阿里云 NPM 镜像:https://npm.aliyun.com
腾讯云 NPM 镜像:https://mirrors.cloud.tencent.com/npm/
华为云 NPM 镜像:https://mirrors.huaweicloud.com/repository/npm/
网易 NPM 镜像:https://mirrors.163.com/npm/
中科院大学开源镜像站:http://mirrors.ustc.edu.cn/
清华大学开源镜像站:https://mirrors.tuna.tsinghua.edu.cn/
腾讯,华为,阿里的镜像站基本上比较全

在使用 npm 访问淘宝镜像时,出现 `certificate has expired` 错误,通常是因为该镜像域名 `https://registry.npm.taobao.org` 的 SSL 证书已经过期。根据已知信息,淘宝镜像已于 2021 年宣布迁移到新域名 `registry.npmmirror.com`,并且旧域名的证书在 2024 年 1 月才完全失效,因此目前使用旧地址的用户会遇到此类问题[^3]。 ### 解决方法 #### 1. 切换到新的淘宝镜像地址 淘宝镜像官方推荐使用新的域名 `registry.npmmirror.com`,可以使用以下命令修改 npm 配置: ```bash npm config set registry https://registry.npmmirror.com ``` 验证是否切换成功: ```bash npm config get registry ``` 如果返回 `https://registry.npmmirror.com`,说明配置已生效[^4]。 #### 2. 临时忽略 SSL 证书错误(不推荐长期使用) 如果暂时无法切换镜像地址,可以忽略 SSL 证书错误,强制 npm 继续执行请求: ```bash npm config set strict-ssl false ``` 注意:此方法会降低安全性,建议仅在临时测试环境中使用,并尽快切换到新的镜像地址[^3]。 #### 3. 使用 nrm 管理多个镜像源 可以通过 `nrm` 工具管理多个 npm 镜像源,方便切换: 安装 nrm: ```bash npm install -g nrm ``` 查看可用镜像: ```bash nrm ls ``` 切换到新的淘宝镜像: ```bash nrm use taobao ``` 这将自动将 npm registry 切换为 `https://registry.npmmirror.com`。 --- ### 其他建议 - **使用官方 npm 镜像**:如果不依赖国内镜像,也可以切换回官方源: ```bash npm config set registry https://registry.npmjs.org ``` - **更新系统时间**:有时系统时间错误也会导致 SSL 证书校验失败,请确保本地系统时间准确。 ---
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值