npm、yarn、pnpm设置国内镜像源

2024-02-29 1628阅读

温馨提示:这篇文章已超过384天没有更新,请注意相关的内容是否还可用!

默认的官方镜像:https://registry.npmjs.org,切换国内淘宝镜像,访问下载更快。

npm、yarn、pnpm设置国内镜像源
(图片来源网络,侵删)

一、npm设置

npm config set registry https://registry.npmmirror.com/

2、查看源

npm config get registry

3、切回官方镜像

npm config set registry https://registry.npmjs.org/

4、npm临时使用

上面那种设置是全局的,以后每次都会自动读取已经设置好的源,如果只是一次性使用,可以使用下面的命令

npm --registry https://registry.npmmirror.com install XXX(模块名)

二、yarn设置

yarn config set registry https://registry.npmmirror.com

2、查看源

yarn config get registry

3、切回官方镜像

yarn config set registry https://registry.yarnpkg.com

三、pnpm设置

pnpm config set registry https://registry.npmmirror.com

2、查看源

pnpm config get registry

3、切回官方镜像

pnpm config set registry https://registry.npmjs.org

四、常见问题

npm修改了下载源,仍然是之前的下载源。或者下载失败、下载到某处停止不动。可以进行如下操作。

(1)清除缓存

(2)将对应项目中的node_modules文件夹以及package-lock.json文件删除。

(3)执行安装 + 需要的下载源。

npm cache clean -f
VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]