方式一
# 設置淘寶鏡像源
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