有很多方法来配置npm的registry地址,下面根据不同情境列出几种比较常用的方法。以淘宝npm镜像举例:

1.临时使用

npm --registry https://registry.npm.taobao.org install express

2.持久使用

npm config set registry https://registry.npm.taobao.org
  • 配置后可通过下面方式来验证是否成功
npm config get registry
npm info express

3.通过cnpm使用

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
  • 使用 
npm install express

注:如果想还原npm仓库地址,只需再把地址配置成npm镜像就可以了

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

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐