npm,cnpm install报:Error: certificate has expired at TLSSocket.onConnectSecure

问题描述

最近发现前端项目 CI/CD 时失败,报下面的错误。npm淘宝镜像源证书过期导致的。
请添加图片描述

[npminstall:get] retry GET https://registry.npm.taobao.org/vue-router after 400ms, retry left 1, error: ResponseError: certificate has expired, GET https://registry.npm.taobao.org/vue-router -1 (connected: true, keepalive socket: false, agent status: {"createSocketCount":42,"createSocketErrorCount":0,"closeSocketCount":35,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":4,"freeSockets":{"registry.npm.taobao.org:443::::::::::::::::::":1,"registry.npmmirror.com:443::::::::::::::::::":1},"sockets":{"registry.npm.taobao.org:443::::::::true::::::::::":5},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}, status: -1, headers: {}, 
stack: Error: certificate has expired
    at TLSSocket.onConnectSecure (_tls_wrap.js:1088:34)
    at TLSSocket.emit (events.js:198:13)
    at TLSSocket._finishInit (_tls_wrap.js:666:8)

问题分析

查看错误日志,发现是在执行 npm install 构建于安装项目时,使用的 npm 镜像源 https://registry.npm.taobao.org 的证书过期了。查看了以下该证书,发现2024.01.22刚过期的。
请添加图片描述

解决方案

可以采用以下几种解决方案中的一种。npm的处理方法,于cnpm一样。

推荐使用第二种方案,因为放弃证书校验,或者使用http的源会有一定的安全风险。

方案1: 不校验证书 cnpm install --insecure;

方案2: 替换镜像源,比如换成华为的 cnpm confg set registry https://mirrors.huaweicloud.com/repository/npm/

方案3: 使用http作为镜像源 cnpm confg set registry http://registry.npm.taobao.org/

可以查看当前配置的npm 镜像源 cnpm config get registry

谨记:忽略证书校验的情况下,连接可能会变得不安全,因为无法验证服务器的真实性和完整性。并且不建议在生产环境中使用。如果可能,建议使用受信任的证书或修复证书校验的问题。

  • 15
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值