npm 源切换到国内镜像

1 阅读1分钟

直接在终端里执行以下命令即可:

image.png

# 切换到淘宝源(推荐)
npm config set registry https://registry.npmmirror.com

# 或者切换到华为云源
npm config set registry https://repo.huaweicloud.com/repository/npm/

# 或者切换到腾讯云源
npm config set registry https://mirrors.cloud.tencent.com/npm/
npm config set registry https://registry.npmmirror.com

验证是否成功:

npm config get registry
# 应该会显示你刚才设置的源地址

如何恢复官方源:

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