胖蔡说技术
随便扯扯

修改yarn、npm、pnpm为国内镜像源

国内由于网络的原因,使用官方的npm、yarn、pnpm访问下载依赖库会很慢,有时候还会出现无法访问的情况,这时候就需要我们给npm、yarn、pnpm换一个国内的镜像源的,一般的我们可以将镜像换成淘宝的源,由于平时比较常用到的关系,所以就简单整理记录下,好之后查看。

  • npm
$npm config get registry #获取当前镜像地址
$npm config set registry https://registry.npm.taobao.org #将镜像设为淘宝镜像
$npm config get registry #查看确认
  • yarn
$yarn config get registry #获取当前镜像地址
$yarn config set registry https://registry.npm.taobao.org #全局替换镜像源
$yarn config get registry
  • pnpm
$pnpm config get registry #获取当前镜像地址
$pnpm config set registry http://registry.npm.taobao.org #全局替换镜像源为淘宝
$pnpm config get registry

操作相似,替换成淘宝镜像后能极大的提高我们的前端库的访问速度。

certificate has expired

近期使用淘宝镜像发现安装报错:

request to https://registry.npm.taobao.org/yocto-queue failed, reason: certificate has expired

其实,早在 2021 年,淘宝就发文称,npm 淘宝镜像已经从 registry.npm.taobao.org 切换到了 registry.npmmirror.com。旧域名也将于 2022 年 5 月 31 日停止服务。

解决方法

清空之前设置的淘宝仓库,修改为新的淘宝仓库:

$ npm config get registry  #查看目前设置的npm镜像仓库
https://registry.npm.taobao.org
$ npm cache clean --force # 清空缓存
$ npm config set registry https://registry.npmmirror.com # 设置成新的淘宝镜像
$ npm config get registry #查看当前npm镜像配置
https://registry.npmmirror.com

其他几个工具的地址修改同上。

赞(3) 打赏
转载请附上原文出处链接:胖蔡说技术 » 修改yarn、npm、pnpm为国内镜像源
分享到: 更多 (0)

请小编喝杯咖啡~

支付宝扫一扫打赏

微信扫一扫打赏