Description
Describe the Bug
If the no-modules target is used and the shim is not parsed in a document, like for example in any kind of worker, any linked module will break.
This problem partially stems from #3069, which now uses new URL('path/to/linked/module', script_src)
.
When using the no-modules target, script_src
can not possibly be correct when not used in a document, which was an oversight from this PR: #3169.
The problem is that if you are in a worker and using importScripts()
, location.href
can never return the path to the imported script, the shim, which is what we want, instead location.href
will return the path to the script that starts the worker, which is not useful in this context and in fact will break any path created for linked modules.
Steps to Reproduce
I can't really get the examples working because wasm-pack doesn't work for me, but the simplest example is using the Atomics.waitAsync
polyfill in Firefox inside a worker, which currently uses linked modules and will try to create a nested worker, which will fail because new URL()
will report an invalid base, for example if the base is a blob.
Solution
I think the solution is two-fold here:
- Remove the fallback to
location.href
ifdocument
is undefined. It is simply impossible to get the path to the shim with the no-modules target, at least as far as I have research. Disable--split-linked-modules
by default when using the no-modules target.
--split-linked-modules
is already disabled by default, but not when usingwasm-bindgen-cli-support
, e.g.wasm-bindgen-test-runner
.