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

相关推荐

  1. 【MySQL】创建用户时报

    2024-07-19 05:44:01       50 阅读
  2. docker commit镜像时报

    2024-07-19 05:44:01       32 阅读
  3. Vue中使用Element-ui时报

    2024-07-19 05:44:01       41 阅读
  4. Nodejs引入模块运行时报

    2024-07-19 05:44:01       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 05:44:01       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 05:44:01       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 05:44:01       62 阅读
  4. Python语言-面向对象

    2024-07-19 05:44:01       72 阅读

热门阅读

  1. Python中的构造方法、析构方法和__str__方法

    2024-07-19 05:44:01       18 阅读
  2. Perl 语言的特点

    2024-07-19 05:44:01       23 阅读
  3. Spark SQL----CREATE TABLE

    2024-07-19 05:44:01       16 阅读
  4. IntelliJ IDEA 和 Eclipse的区别

    2024-07-19 05:44:01       24 阅读
  5. 【Android】基础—基本布局

    2024-07-19 05:44:01       15 阅读
  6. Docker & Ubuntu & Milvus 2.4 windows 详细安装攻略

    2024-07-19 05:44:01       16 阅读
  7. c# excel转pdf

    2024-07-19 05:44:01       20 阅读
  8. (二)C++之类与对象

    2024-07-19 05:44:01       21 阅读
  9. C++派生类对基类成员的访问

    2024-07-19 05:44:01       21 阅读
  10. junit mockito service

    2024-07-19 05:44:01       22 阅读