const worker = new Worker(
new URL("./worker.ts", import.meta.url),
{ type: "module" },
);
worker.postMessage({});
Expected behavior
No errors.
Additional context
This seems to be a problem with the injected HMR code that assumes a standard browser context, but doesn't work in a Web Worker context (where globals like document are not defined).
Workaround
Plonking globalThis.document = {} at the top of the worker code makes it sort of usable, but HMR updates will still crash it.
Describe the bug If you attempt to start a Platform.worker app in a Web Worker script, you get
Reproducible repo
The gist is:
Worker.elm:
worker.ts:
index.ts:
Expected behavior No errors.
Additional context This seems to be a problem with the injected HMR code that assumes a standard browser context, but doesn't work in a Web Worker context (where globals like
document
are not defined).Workaround
Plonking
globalThis.document = {}
at the top of the worker code makes it sort of usable, but HMR updates will still crash it.