【发布时间】:2021-02-18 15:32:17
【问题描述】:
我正在尝试在我通过 Firefox 85 中的 HTML 加载(或者更确切地说,我不会加载!)的脚本中进行条件导入(ES6 风格的 Javascript)。
这是脚本:(myscript.js)
let ENVIRONMENT_IS_NODE = false;
let require;
if (ENVIRONMENT_IS_NODE) {
const {createRequire} = await import('module');
require = createRequire(import.meta.url);
}
这是我的 HTML 页面:(example.html)
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
</head>
<body>
<script type="module" src="myscript.js"></script>
<!-- I also tried with async, but that did not change anything: -->
<!--script async type="module" src="myscript.js"></script-->
HELLO
</body>
</html>
另外,我知道在 Firefox 中保护此功能的标志,所以我负责将 about:config 中的 javascript.options.experimental.top_level_await 设置为 true。
但我在加载页面时仍然在 javascript 控制台中收到以下错误:
Uncaught SyntaxError: top level await is not currently supported
有关信息,只要设置了正确的标志 (#enable-javascript-harmony),Chrome 88 上的同一页面就可以正常加载。
为什么它不能在 Firefox 85 上运行? 我是不是做错了什么?
Here 和 here 我得到确认,开发工作已经完成并随版本 85 一起发布,应该使用标志启用。
编辑: 我刚刚填写了a bug report。让我们看看开发者怎么说。
【问题讨论】:
标签: javascript firefox ecmascript-6 async-await es6-modules