Closed Bug 1558780 Opened 5 years ago Closed 5 years ago

Add support for Web Worker type="module" (ES6 module imports in worker scripts)

Categories

(Core :: JavaScript Engine, enhancement)

69 Branch
enhancement
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1247687

People

(Reporter: u591120, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36

Steps to reproduce:

main.js:

let w = new Worker("./myWorker.js", {type:"module"});

myWorker.js:

import MyModule from "./MyModule.js";
self.onmessage = () => {
  // ...
}

Actual results:

Firefox doesn't support ES6 import statements in workers.

Expected results:

Chrome has had module workers behind a flag for a while now. It would be great if firefox could support {type:"module"} soon as well. Currently I'm forced to either not use ES6 module imports/exports in the libraries I'm making, or make two copies of the same library (one where the files are linked together with import and export, and another where there are no imports/exports - and instead all the scripts are imported at the top of my worker script (in the correct order, which can get complicated). There are obviously other workarounds for this (e.g. build pipelines), but it would be super nice to not have to deal with that for simple projects.

Here's the chromestatus page:
https://www.chromestatus.com/feature/5761300827209728

Here's the spec:
https://html.spec.whatwg.org/multipage/workers.html#workeroptions

Bugbug thinks this bug is a enhancement, but please change it back in case of error.

Type: defect → enhancement

This being an enhancement I will set a component to it and further someone from dev's team could take a look on this. As well there is a meta bug about the support of ES6 modules.
Thanks.

Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.