遇到 npm install报错 certificate has expired是因为淘宝镜像源(registry.npm.taobao.org)
request to https://registry.npm.taobao.org/yargs-parser/download/yargs-parser-18.1.2.tgz failed, reason: certificate has expired npm install报这个错误
遇到 npm install
报错 certificate has expired
是因为淘宝镜像源(registry.npm.taobao.org
)的 SSL 证书已过期。以下是解决方案:
方法 1:更新 npm 镜像源(推荐)
淘宝镜像源已迁移至新域名 npmmirror.com
,旧域名已停用。请切换至新源:
# 设置新淘宝镜像源
npm config set registry https://registry.npmmirror.com# 清除 npm 缓存
npm cache clean --force
重新运行 npm install
。
方法 2:临时关闭 SSL 验证(不推荐)
仅作为临时解决方案(存在安全风险):
npm config set strict-ssl false
安装完成后务必恢复设置:
npm config set strict-ssl true
方法 3:切换回官方 npm 源
如果不需要国内加速,可改用 npm 官方源:
npm config set registry https://registry.npmjs.org
补充说明
-
检查当前源:
npm config get registry
确保返回
https://registry.npmmirror.com
或官方源。 -
项目级配置:
若项目中有.npmrc
文件,检查是否包含旧镜像地址并更新。 -
系统时间问题:
确认系统时间准确(证书错误可能由时间偏差引起)。
执行以上操作后重新运行 npm install
即可解决。推荐优先使用 方法 1 更新镜像源。