![](/img/trans.png)
[英]How do I solve __WEBPACK_IMPORTED_MODULE_1__.default is undefined
[英]How do I access the default export of a module imported via a Webpack dynamic import promise?
問題說明了一切。 谷歌搜索返回了大量 ES6 導入語法的示例,但我使用的是 Webpack “動態導入”。 在下面的代碼中,我展示了帶有注釋結果的消費者文件:
模塊文件:
export default class Main {
init() {
console.log("Main init");
}
}
消費者檔案:
import(/* webpackChunkName: "main" */ "./main").then(Main => {
init(Main);
});
function init(Main) {
console.log(Main); // "Module"
const main = new Main.Main(); // not a constructor
const main = new Main(); // not a constructor
const main = new Main.getDefault(); // not a constructor
}
我需要訪問模塊默認值,例如:
const mainclass = Main.default;
const main = new mainclass();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.