方式一
# 设置淘宝镜像源
npm config set registry https://registry.npm.taobao.org
# 查看使用的镜像源
npm config get registry
# 安装淘宝镜像源
npm install -g cnpm --registry=https://registry.npm.taobao.org
方式二
可使用官方推荐的 cnpm 命令行工具代替默认的 npm
:
npm install -g cnpm --registry=https://registry.npm.taobao.org
注意:有时使用 cnpm 安装的路径可能回存在问题,在使用react-native开发应用时会出现问题。此时可以使用nrm切换淘宝源:
npx nrm use taobao
# 以下方式切换回官方源
npx nrm use npm