代码配置
// 下面的 url 就是你所要配置的镜像地址,替换一下就可以了
npm config set registry url
nrm
如果你不想记上面的命令,那么 nrm 就是一个很好的选择。使用 nrm 就可以很容易的实现对 npm 镜像进行配置。
下载 nrm
npm i -g nrm
使用
nrm ls // 查看所支持的镜像列表
nrm use taobao // 配置淘宝镜像
如果你使用出现了这样的报错: Must use import to load ES Module ,原因也很简单 nrm v9.0.0 是 ES Module 规范的包,Node 则是 Commonjs 规范,只需要改变一下 nrm 的版本就可以了。
npm install -g nrm open@8.4.2 --save
参考
nrm安装后报错 require() of ES modules is not supported. - 江的博客 (mate98.cn)