【发布时间】:2020-06-26 22:22:42
【问题描述】:
我正在尝试在动态导入的模块中导出冻结的对象,但它失败了。
我的主要模块是:
import ('./hello.mjs').then(function (o) {
o.hello();
});
我的导入模块 hello.mjs 有这样的代码:
function hello () {
console.log('Hello');
}
export default Object.freeze({ hello });
程序在控制台中失败并出现此错误:
TypeError: o.hello is not a function at main.mjs:2
但是,如果我使用简单的导出,像这样:
function hello () {
console.log('Hello');
}
export { hello };
...然后就可以了。导出默认冻结对象适用于非动态模块导入。为什么动态模块导入的行为不同,我可以做些什么来纠正这个问题?
【问题讨论】:
标签: javascript dynamic import module export