npm切换镜像源

npm切换镜像源

安装 npm & nodejs

Linux(RHEL系列)安装npm & nodejs

1
2
yum -y install npm
yum -y install node

查看镜像源使用状态:npm config get registry
切换到官方镜像源:npm config set registry http://www.npmjs.org
切换到淘宝镜像源:npm config set registry http://registry.npm.taobao.org

切换npm源:

1
npm config set registry http://registry.npm.taobao.org

安装nrm插件

安装nrm插件:

1
npm install nrm -g

查看支持镜像地址:

1
2
3
4
5
6
7
nrm ls
npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.npmmirror.com/
npmMirror ---- https://skimdb.npmjs.com/registry/

如果出现如下错误提示:版本冲突

1
2
3
4
5
6
7
8
9
10
11
Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/nrm/node_modules/open/in
[root@Centos9-Stream blog]# nrm ls
/usr/local/lib/node_modules/nrm/cli.js:9
const open = require('open');
^

Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/nrm/node_modules/open/index.js from /usr/local/lib/node_modules/nrm/cli.js not supported.
Instead change the require of index.js in /usr/local/lib/node_modules/nrm/cli.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/usr/local/lib/node_modules/nrm/cli.js:9:14) {
code: 'ERR_REQUIRE_ESM'
}

解决方案:

1
npm install -g nrm open@8.4.2 --save

——END——