faq,

Tools - After nrm installation, the execution reports an open module error

中文阅读

Problem Description

After installing ‘nrm’, an open module error is reported when executing the command.

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'
 }

Solution

open v9.0.0 is the ES Module version of the package, but nrm requires the CommonJs package. Therefore, execute the following command to install open v8.x.x.

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

verify

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.

Reference


CatchZeng
Written by CatchZeng Follow
AI (Machine Learning) and DevOps enthusiast.