问题现象
安装完 nrm,执行命令时报 open 模块错误。
1 2 3 4 5 6 7 8 9 10
$ 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' }
解决方法
open v9.0.0 是 ES Module 版本的包,但是 nrm 需要 CommonJs 包。因此,执行以下命令安装 open v8.x.x 即可。
1
$ npm install -g nrm open@8.4.2 --save
验证
1 2 3 4 5 6 7 8 9 10
$ 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/ $ nrm current You are using npm registry.
Tools - After nrm installation, the execution reports an open module error