简体   繁体   English

如何访问通过 Webpack 动态导入 promise 导入的模块的默认导出?

[英]How do I access the default export of a module imported via a Webpack dynamic import promise?

Question says it all.问题说明了一切。 Googling returns plenty of examples of ES6 import syntax, but I'm using a Webpack "dynamic import".谷歌搜索返回了大量 ES6 导入语法的示例,但我使用的是 Webpack “动态导入”。 In the below code, I've shown my consumer file with commented results:在下面的代码中,我展示了带有注释结果的消费者文件:

Module file:模块文件:

export default class Main {
  init() {
    console.log("Main init");
  }
}

Consumer file:消费者档案:

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
}

I needed to access the module default like:我需要访问模块默认值,例如:

const mainclass = Main.default;
const main = new mainclass();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何解决 __WEBPACK_IMPORTED_MODULE_1__.default is undefined - How do I solve __WEBPACK_IMPORTED_MODULE_1__.default is undefined 如何修复此错误 TypeError: _components_firebase_Firebase__WEBPACK_IMPORTED_MODULE_2__.default.auth is not a function - How do I fix this error TypeError: _components_firebase_Firebase__WEBPACK_IMPORTED_MODULE_2__.default.auth is not a function 类型错误:react__WEBPACK_IMPORTED_MODULE_2___default(...) 不是函数。 我该如何解决这个问题? - TypeError: react__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function. How do I solve this? 如何使用 Jasmine 监视通过 ES6 默认导出导入的 function? - How do I use Jasmine to spy on a function that is imported via an ES6 default export? 如何通过webpack导入引导程序? - How do I import bootstrap via webpack? 如何使用Webpack 4公开javascript模块的默认导出对象? - How do I expose a javascript module's default export object with Webpack 4? webpack 导入模块未找到错误:未捕获类型错误:_useFetch__WEBPACK_IMPORTED_MODULE_0__["default"](...) 为 null - webpack import module not found error: Uncaught TypeError: _useFetch__WEBPACK_IMPORTED_MODULE_0__["default"](...) is null 如何从导入模块的 Promise 中导出? - How to export from within an imported module's Promise? v-on 处理程序中的错误(Promise/async):“TypeError:axios__WEBPACK_IMPORTED_MODULE_14___default.a.todo 不是函数” - Error in v-on handler (Promise/async): "TypeError: axios__WEBPACK_IMPORTED_MODULE_14___default.a.todo is not a function" React/Firebase 错误“未捕获(承诺中)TypeError:(0,_firebase__WEBPACK_IMPORTED_MODULE_1__.default)不是函数” - React/Firebase error "Uncaught (in promise) TypeError: (0 , _firebase__WEBPACK_IMPORTED_MODULE_1__.default) is not a function"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM