npm 使用淘宝镜像及切换回官方源

一、npm 使用淘宝镜像

1. 配置命令-第一个命令是旧版的,第二个为新版的

npm config set registry https://registry.npm.taobao.org
npm config set registry https://registry.npmmirror.com/

2. 验证命令

npm config get registry

返回结果为 https://registry.npm.taobao.org , 说明淘宝镜像配置成功

3. 使用cnpm安装

说明:因为npm安装插件是从国外服务器下载,受网络影响大,可能出现异常,所以我们乐于分享的淘宝团队干了这事。!来自官网:“这是一个完整 npmjs.org 镜像,你可以用此代替官方版本(只读),同步频率目前为 10分钟 一次以保证尽量与官方服务同步。”

 -g:全局安装。

npm install -g cnpm --registry=https://registry.npm.taobao.org
// 解决安装卡顿或无法安装
// 注册模块
npm set registry https://registry.npm.taobao.org
// node-gyp 编译依赖 node 源码镜像
npm set disturl https://npm.taobao.org/dist
// 清空缓存
npm cache clean --force
// 安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org

安装完后最好查看其版本号cnpm -v或关闭命令提示符重新打开,安装完直接使用可能会出现错误

4. 使用cnpm

cnpm跟npm用法完全一致,只是在执行命令时将npm改为cnpm(以下操作将以cnpm代替npm)。

二、npm 切换回官方源

删除地址即可恢复默认源

npm config delete registry

或者直接修改为原本的源

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

猜你喜欢

转载自blog.csdn.net/XueZePeng18729875380/article/details/129519153