npm install时报错 reason: certificate has expired

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

bash 复制代码
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模式。

bash 复制代码
# 强制清除 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)重新运行安装命令

bash 复制代码
npm install
相关推荐
老黑8 分钟前
开源工具 AIDA:给 AI 辅助开发加一个数据采集层,让 AI 从错误中自动学习(Glama 3A 认证)
前端·react.js·ai·nodejs·cursor·vibe coding·claude code
jessecyj23 分钟前
Spring boot整合quartz方法
java·前端·spring boot
苦瓜小生35 分钟前
【前端】|【js手撕】经典高频面试题:手写实现function.call、apply、bind
java·前端·javascript
天若有情67342 分钟前
前端HTML精讲03:页面性能优化+懒加载,搞定首屏加速
前端·性能优化·html
踩着两条虫1 小时前
AI驱动的Vue3应用开发平台深入探究(十):物料系统之内置组件库
android·前端·vue.js·人工智能·低代码·系统架构·rxjava
swipe1 小时前
AI 应用里的 Memory,不是“保存聊天记录”,而是管理上下文预算
前端·llm·agent
慧一居士2 小时前
nuxt3 项目和nuxt4 项目区别和对比
前端·vue.js
威联通安全存储2 小时前
破除“重前端、轻底层”的数字幻象:如何夯实工业数据的物理底座
前端·python
inksci2 小时前
Js生成安全随机数
前端·微信小程序
吴声子夜歌3 小时前
TypeScript——泛型
前端·git·typescript