版本不兼容Error [ERR_REQUIRE_ESM]: require() of ES Module C:\... from C:\...

1,736 阅读1分钟

版本不兼容Error [ERR_REQUIRE_ESM]: require() of ES Module C:\... from C:\...

在pull了别人的仓库之后,老规矩,先install各种依赖,但是有时候插件和依赖版本之间的不兼容,会导致无法继续。

D:\WebProjects\****>nrm *****
C:\****\nodejs\node_global\node_modules\nrm\cli.js:9
const open = require('open');
             ^

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

可以看到控制台的修改建议是将require改成import,来符合CommonJS的标准。 找到这个文件 C:\****\nodejs\node_global\node_modules\nrm\cli.js

定位到9:14,将

const open = require('open');

改成

const open = import('open');