0


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

一、npm 使用淘宝镜像

  1. 配置命令-第一个命令是旧版的,第二个为新版的
npm config set registry https://registry.npm.taobao.org
npm config set registry https://registry.npmmirror.com/
  1. 验证命令
npm config get registry

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

  1. 使用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或关闭命令提示符重新打开,安装完直接使用可能会出现错误

  1. 使用cnpm

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

二、npm 切换回官方源

删除地址即可恢复默认源

npm config delete registry

或者直接修改为原本的源

npm config set registry https://registry.npmjs.org/
标签: npm 前端 node.js

本文转载自: https://blog.csdn.net/XueZePeng18729875380/article/details/129519153
版权归原作者 XueZePeng18729875380 所有, 如有侵权,请联系我们删除。

“npm 使用淘宝镜像及切换回官方源”的评论:

还没有评论