您的位置:首页 > 汽车 > 时评 > npm install时报错 reason: certificate has expired

npm install时报错 reason: certificate has expired

2024/10/18 13:09:47 来源:https://blog.csdn.net/qq_39512532/article/details/140525421  浏览:    关键词:npm install时报错 reason: certificate has expired

在VS code中导入新项目,执行npm install时报错:

npm warn old lockfile Could not fetch metadata for @antv/g@3.4.10 FetchError: request to https://registry.npm.taobao.org/@antv%2fg failed, reason: certificate has expirednpm warn old lockfile     at ClientRequest.<anonymous> (D:\softFile\Node.js\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm warn old lockfile     at ClientRequest.emit (node:events:519:28)
npm warn old lockfile     at _destroy (node:_http_client:880:13)
npm warn old lockfile     at onSocketNT (node:_http_client:900:5)
npm warn old lockfile     at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
npm warn old lockfile   code: 'CERT_HAS_EXPIRED',
npm warn old lockfile   errno: 'CERT_HAS_EXPIRED',
npm warn old lockfile   type: 'system'
npm warn old lockfile }

由以下命令可知npm引用了淘宝镜像:

原因:淘宝证书过期

解决办法:

方法一:清除 npm 的缓存,然后禁用 strict-ssl模式。

# 强制清除 npm 的缓存。npm 在安装包时会将下载的包缓存到本地,以便下次使用时可以直接从缓存中获取,加快安装速度。
npm cache clean --force# 禁用 npm 的 strict-ssl模式。默认情况下,npm 在下载包时会验证 SSL 证书的有效性,以确保安全性。这里禁用 SSL 严格模式,允许使用自签名或无效的 SSL 证书进行下载,此方法就会忽略淘宝证书过期问题。
npm config set strict-ssl false# 重新运行
npm install

方法二:由于在2021 年,淘宝发文称,npm 淘宝镜像已经从 registry.npm.taobao.org 切换到了 registry.npmmirror.com。旧域名也将于 2022 年 5 月 31 日停止服务, HTTPS 证书也到期了。(建议使用该方法

1)清空缓存,修改镜像

# 清空缓存
npm cache clean --force# 修改镜像(管理员运行命令行)
npm config set registry https://registry.npmmirror.com

2)删除系统用户目录下.npmrc和.yarnrc文件,以及修改.vuerc文件(存在的话,修改"useTaobaoRegistry"为true)

3)重新运行安装命令

npm install

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com