Pana / nrm

NPM registry manager, fast switch between different registries: npm, cnpm, nj, taobao
MIT License
2.77k stars 242 forks source link

Fix ERR_REQUIRE_ESM #149

Open zhangsean opened 1 year ago

zhangsean commented 1 year ago
$ nrm
C:\Users\sean\AppData\Roaming\npm\node_modules\nrm\cli.js:9
const open = require('open');
             ^

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

Node.js v18.12.0
LuoRiWuSheng commented 1 year ago
$ nrm
C:\Users\sean\AppData\Roaming\npm\node_modules\nrm\cli.js:9
const open = require('open');
             ^

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

Node.js v18.12.0

你这个 ESM 和 CommonJS 2种规范 引入包, 应该是不行的

低版本的node 应该会报错

LuoRiWuSheng commented 1 year ago

我在我本地 调整了 包的 版本, lock 包的版本, npm link 调试了一下, 是没问题的 对应提交了一个 merge request https://github.com/Pana/nrm/pull/148

zhangsean commented 1 year ago

期待新版本发布,我本地再试试!