国内镜像
常用的国内镜像:
淘宝镜像 https://registry.npmmirror.com
腾讯云镜像 https://mirrors.cloud.tencent.com/npm/
华为云镜像 https://repo.huaweicloud.com/repository/npm/
CNPM(阿里系) https://r.cnpmjs.org/
清华大学镜像 https://mirrors.tuna.tsinghua.edu.cn/help/npm/
npm
bash
# 查询当前使用的镜像源
npm get registry
# 设置为淘宝镜像源
npm config set registry https://registry.npmmirror.com/
# 还原为官方镜像源
npm config set registry https://registry.npmjs.org/
pnpm
bash
# 查询当前使用的镜像源
pnpm get registry
# 设置为淘宝镜像源
pnpm config set registry https://registry.npmmirror.com/
# 还原为官方镜像源
pnpm config set registry https://registry.npmjs.org/
yarn
bash
# 查询当前使用的镜像源
yarn config get registry
# 设置为淘宝镜像源
yarn config set registry https://registry.npmmirror.com/
# 还原为官方镜像源
yarn config set registry https://registry.yarnpkg.com/
临时指定镜像
bash
npm --registry https://registry.npmjs.org/ install <package-name>
pnpm --registry https://registry.npmjs.org/ add <package-name>
yarn add <package-name> --registry=https://registry.yarnpkg.com/