npm淘宝镜像源更新

目录

前情提要:

背景:

镜像源更新:

清楚缓存:

直接切换镜像源:

注:npm

补充:

错误解释:

解决方法:


前情提要:

2024 /1 /22 ,registry.npm.taobao.org淘宝镜像源的SSL证书过期了,这就使得我们在通过该镜像源安装一些软件包的时候会报错。

所以我们只需要更换镜像源为新的:registry.npmmirror.com

背景:

本文就是因为我在更新一个项目的依赖时出现报错:

ERR_PNPM_META_FETCH_FAIL  GET https://registry.npm.taobao.org/pnpm: request to https://registry.npm.taobao.org/pnpm failed, reason: certificate has expired

先解释一下这个报错:

无法从淘宝的npm镜像源(registry.npm.taobao.org)获取 pnpm 包的元数据,因为该源的SSL证书已经过期

所以需要更换镜像源为新的:registry.npmmirror.com

镜像源更新:

我用的是pnpm,所以优先讲解pnpm的解决方法

清楚缓存:
  1. npm cache clean --force
  2. pnpm store prune

        若使用npm不需要第二步(清楚缓存的2.)

直接切换镜像源:
  1. # npm 官方源
    pnpm config set registry https://registry.npmjs.org
    
  2. # 新taobao 源
    pnpm config set registry https://registry.npmmirror.com

查看 C盘/user /你的用户名(user/xxx/.npmrc) 文件目录下的 .npmrc 中的源地址有没有变成新的

如果更新好了就不用管了,如果还是原来的可以手动换成新的源:registry.npmmirror.com

注:npm

若使用的包管理器时npm:

  • 只需将上述步骤代码的pnpm改为npm
  • 且不需要清楚缓存的第二步(清楚缓存的2.)

补充:

此时如果你直接去更新项目中的某个依赖,而不是所有依赖,例如只想更新elementplus,会出现:pnpm install element-plus@latest  ERR_PNPM_REGISTRIES_MISMATCH  This modules directory was created using the following registries configuration: {"default":"https://registry.npm.taobao.org/"}. The current configuration is {"default":"https://registry.npmmirror.com/"}. To recreate the modules directory using the new settings, run "pnpm install".

错误解释:

 ERR_PNPM_REGISTRIES_MISMATCH 表示你正在尝试使用与最初创建 node_modules 目录时不同的源来安装依赖项。在这个案例中,node_modules 目录是用淘宝的 npm 镜像源 https://registry.npm.taobao.org/ 创建的,但是你当前的配置是另一个源 https://registry.npmmirror.com/

解决方法:

按照错误消息中的建议,使用当前配置的源来重新创建 node_modules 目录

删除现有的 node_modules 和 lock 文件:

rm -rf node_modules pnpm-lock.yaml

重新安装依赖项:

pnpm install

至此问题解决😃

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值