nrm安装后报错 Error [ERR_REQUIRE_ESM]: require()

458 阅读1分钟

今日在mac安装nrm 后,使用命令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'

}

  


Node.js v19.8.1

后经过查询原因:应该使用 open 的 CommonJs规范的包 ,现在 open v9.0.0 是 ES Module 版本的包 image.png

解决方法:npm install -g nrm open@8.4.2 --save

从github的issues复制来的,用于记录 参考链接juejin.cn/post/721296…

使用 npm install -g nrm 后解决问题

(base) gardeMacBook-Pro:crazysgame xxxxx$ npm install -g nrm open@8.4.2 --save

npm WARN deprecated har-validator@5.1.5: this library is no longer supported

npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

  


added 4 packages, removed 38 packages, and changed 69 packages in 3s

  


11 packages are looking for funding

  run `npm fund` for details

(base) gardeMacBook-Pro:crazysgame xxxxx$ 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/