Error with conditional import using top-level-await
Categories
(Core :: JavaScript Engine, task, P2)
Tracking
()
People
(Reporter: maus.almeo, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36
Steps to reproduce:
I'm trying to do a conditional import (Javascript of ES6 flavour) in a script that I load (or rather, that I would not load!) through HTML in Firefox 85.
Here is the script: (myscript.js)
let ENVIRONMENT_IS_NODE = false;
let require;
if (ENVIRONMENT_IS_NODE) {
const {createRequire} = await import('module');
require = createRequire(import.meta.url);
}
Here is my HTML page: (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>
Also, I am aware of the flag protecting this feature in Firefox, so I took care of setting javascript.options.experimental.top_level_await to true in about:config.
I then launched a simple server in the same directory as these two files:
$ python3 -m http.server 9006
And then I launched Firefox:
$ firefox http://localhost:9006/example.html
Actual results:
But I still get the following error in the javascript console upon loading the page:
Uncaught SyntaxError: top level await is not currently supported
Expected results:
For information, the same page is loading fine on Chrome 88, provided the proper flag is set too (#enable-javascript-harmony).
Here and here I got the confirmation that the development work is already done and shipped with the release 85, and should be enabled with the flag.
Comment 1•5 years ago
|
||
The pref has an effect only on Nightly build.
Will fix the documentation to mention that.
// Require top level await disabled outside of nightly.
bool topLevelAwaitEnabled = false;
#ifdef NIGHTLY_BUILD
topLevelAwaitEnabled =
Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.top_level_await");
#endif
Comment 2•5 years ago
|
||
opened PR to fix the doc https://github.com/mdn/browser-compat-data/pull/9176
| Reporter | ||
Comment 3•5 years ago
|
||
Hi, thank you a lot for your help!! This solves my problem.
Is there a planned public release for which the flag will be enabled, though?
(I suppose it will not be limited to Nightly forever)
| Reporter | ||
Comment 5•5 years ago
|
||
Thanks a lot!! Ok, I see it is under active development!! ^^
Comment 6•5 years ago
|
||
Hi Almeo,
Thanks for getting in touch. With regards to the public release: we have plans to release this soon. The specification is currently undergoing a change, which will alter the loading behaviour if it lands. This should be decided sometime in early March. We have a branch with the proposed new behaviour and are just waiting on that.
Updated•5 years ago
|
Comment 7•5 years ago
|
||
I don't think we need this bug now that TLA is enabled.
Description
•