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 中使用
得到的库版本是13.0.0
| 归档时间: |
|
| 查看次数: |
794 次 |
| 最近记录: |