Bug 164860 - JS Modules in Workers
Summary: JS Modules in Workers
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on: 164425
Blocks: 147340 192329 165724
  Show dependency treegraph
 
Reported: 2016-11-17 01:18 PST by Yusuke Suzuki
Modified: 2020-12-21 04:22 PST (History)
23 users (show)

See Also:


Attachments
Patch (27.74 KB, patch)
2020-06-19 16:47 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2016-11-17 01:18:38 PST
...
Comment 1 Saleh Abdel Motaal 2018-07-07 05:59:18 PDT
It seems that support `new Worker(…, {type: "module"})` is limited or missing.

In a project that uses only pure ES modules served using a very basic express server (ie express.static) over http://127.0.0.1:8080 or http://localhost:8080 a worker module with static import statements:

```
import {…} from '…'
```

Throws: 
  SyntaxError: Unexpected token '{'. import call expects exactly one argument.

It should be noted that those static import statements are synthesized using rollup and the resulting files sometimes include one or more variable declarations before the occurrence of the import statements.

The same project does not throw in Chrome.
Comment 2 Guy Bedford 2019-09-11 11:47:33 PDT
Note that supporting dynamic `import()` in Web Workers can also be a first start along these lines.
Comment 3 Tobias Uhlig 2019-11-03 12:02:36 PST
Just stumbled on this ticket and am quite surprised that it did not get way more comments yet.

I am crafting a web workers driven ES8 framework, so module support for workers (including dynamic imports) is one of the key features lacking in Safari.

In Chrome this works already for close to a year using the experimental web plattform features and now got the Label Target-80.

Without the type="module" support, applications have to use build tools like Webpack, which is slowing the web development speed down by a long shot!

Please be aware, that this ticket should also include the module type for shared & service workers.

I recommend to make it a high priority epic.

Thanks & best regards
Tobias
Comment 4 Tobias Uhlig 2019-12-20 13:06:22 PST
A quick update on the current status would be appreciated.

The new framework is online now and already at 227 github stars (December 20):
https://github.com/neomjs/neo

Here are the online examples, which according to the specs should work in every modern browser:
https://neomjs.github.io/pages/

It makes me a bit sad to see Safari falling behind on an such important topic.

https://html.spec.whatwg.org/multipage/workers.html#module-worker-example

Hoping you will catch up!

Best regards & happy holiddays,
Tobias
Comment 5 Radar WebKit Bug Importer 2020-06-14 19:44:14 PDT
<rdar://problem/64348230>
Comment 6 Yusuke Suzuki 2020-06-19 16:47:17 PDT
Created attachment 402347 [details]
Patch

WIP