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

你好,我是悦创。

我的博客网站阅读更佳:https://bornforthis.cn/blog/vuepress/08.html

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

1. npm 设置

::: code-tabs

  1. 查看源
bash 复制代码
npm config get registry
  1. 设置淘宝源
bash 复制代码
npm config set registry https://registry.npmmirror.com/
  1. 切回官方镜像
bash 复制代码
npm config set registry https://registry.npmjs.org/
  1. npm 临时使用
bash 复制代码
# 上面那种设置是全局的,以后每次都会自动读取已经设置好的源,如果只是一次性使用,可以使用下面的命令
npm --registry https://registry.npmmirror.com install XXX(模块名)

2. yarn 设置

  1. 查看源
bash 复制代码
yarn config get registry
  1. 设置淘宝源
bash 复制代码
yarn config set registry https://registry.npmmirror.com
  1. 切回官方镜像
bash 复制代码
yarn config set registry https://registry.yarnpkg.com

3. pnpm 设置

  1. 查看源
bash 复制代码
pnpm config get registry
  1. 设置淘宝源
bash 复制代码
pnpm config set registry https://registry.npmmirror.com
  1. 切回官方镜像
bash 复制代码
pnpm config set registry https://registry.npmjs.org

4. 常见问题

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

  1. 清除缓存
  2. 将对应项目中的 node_modules 文件夹以及 package-lock.json 文件删除。
  3. 执行安装 + 需要的下载源。
相关推荐
excel1 天前
为什么在 Three.js 中平面能产生“起伏效果”?
前端
excel1 天前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼1 天前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping1 天前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
石金龙1 天前
[译] Composition in CSS
前端·css
白水清风1 天前
微前端学习记录(qiankun、wujie、micro-app)
前端·javascript·前端工程化
Ticnix1 天前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
用户22152044278001 天前
new、原型和原型链浅析
前端·javascript
阿星做前端1 天前
coze源码解读: space develop 页面
前端·javascript
叫我小窝吧1 天前
Promise 的使用
前端·javascript