当使用 npm install <package>
时,由于 NPM 默认镜像站是在国外的原因,会导致下载速度非常慢,甚至下载失败。
可以切换为国内的 淘宝镜像站
临时使用(仅对本次有效)
npm install <package> --registry https://registry.npmmirror.com
长期使用(推荐,如果需要 发布 NPM 包 的话,不能使用这种配置,需要改回原镜像源)
npm config set registry https://registry.npmmirror.com
或者使用 淘宝镜像站 提供的 cnpm
- 先安装
cnpm
# MacOS or Linux 在前面需要加上 sudo,然后输入密码。
npm install -g cnpm
- 然后使用
cnpm
替代npm
cnpm install <package>
还原 NPM 官方的镜像源
npm config set registry https://registry.npmjs.org/
验证是否配置成功
npm config get registry
参考连接
- https://npm.taobao.org/
- https://docs.npmjs.com/cli/v7/using-npm/registry