如何从 CommonJS 模块导入 ESM Javascript 文件?得到。错误:不支持

Vip*_*esh 5 javascript commonjs node.js es6-modules node.js-got

我的项目完全是用 CommonJS 模块编写的,我无法更改它。我正在尝试使用一个 ESM 库。该库是 Got 库(https://github.com/sindresorhus/got)。

这是我的代码

const request = require('request');
const Promise = require('bluebird');
// require('./wrapped-got');
var wrappedgot = null;

function HTTPRequestV2(hostURL, defaultOptions) {
    this.hostUrl = hostURL;
    this.requestWrapper = request.defaults(defaultOptions);
}


HTTPRequestV2.prototype.init = async function(){
    wrappedgot = await import('got');
    /*return import('got')
        .then(({default: theDefault}) => {
            wrappedgot= theDefault;
            console.log(theDefault);

        });
    console.log(wrappedgot);*/
};
Run Code Online (Sandbox Code Playgroud)

但在运行此命令时,我收到错误Not Supported on thewrappedgot = wait import('got'); 线

我尝试按照问题页面中的建议使用动态导入函数的解决方法,但由于上述错误而失败 https://github.com/sindresorhus/got/issues/1789

甚至尝试运行他们的示例代码,但也失败并出现相同的错误 https://gist.github.com/szmarczak/0f2b70b2a1ed52a56a6d391ac02d094d

- - - 更新 - - - -

我使用的是 Node 版本 12.14.1,它支持异步和等待。我读过 SO,它已在 Node Version 10 中使用

在 Node.js 上使用动态 import() 函数

得到的库版本是13.0.0

Que*_*tin 0

Node.js 12.x 不支持Node 13.2.0 中引入的动态导入。此外,对 Node.js 12.x 的安全支持结束已经一年多了。

升级到Node.Js 的当前版本。