国内由于网络的原因,使用官方的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。旧