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
相关推荐
DT——1 小时前
Vite项目中eslint的简单配置
前端·javascript·代码规范
学习ing小白4 小时前
JavaWeb - 5 - 前端工程化
前端·elementui·vue
真的很上进4 小时前
【Git必看系列】—— Git巨好用的神器之git stash篇
java·前端·javascript·数据结构·git·react.js
胖虎哥er4 小时前
Html&Css 基础总结(基础好了才是最能打的)三
前端·css·html
qq_278063714 小时前
css scrollbar-width: none 隐藏默认滚动条
开发语言·前端·javascript
.ccl4 小时前
web开发 之 HTML、CSS、JavaScript、以及JavaScript的高级框架Vue(学习版2)
前端·javascript·vue.js
小徐不会写代码4 小时前
vue 实现tab菜单切换
前端·javascript·vue.js
林太白5 小时前
❤Node09-用户信息token认证
数据库·后端·mysql·node.js
2301_765347545 小时前
Vue3 Day7-全局组件、指令以及pinia
前端·javascript·vue.js
ch_s_t5 小时前
新峰商城之分类三级联动实现
前端·html