Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import.meta.url rewrite doesn't work in web worker #5087

7 tasks done
cedeber opened this issue Sep 25, 2021 · 1 comment · Fixed by #5113
7 tasks done

import.meta.url rewrite doesn't work in web worker #5087

cedeber opened this issue Sep 25, 2021 · 1 comment · Fixed by #5113


Copy link

cedeber commented Sep 25, 2021

Describe the bug

The plugin that rewrites import.meta.url uses window.location which is not available in web workers.
If I am right, I think this happens here:

)})[${rawUrl}], window.location)`

I believe that using `(window ?? self).location should fix the issue.


Generating WebAssembly with wasm-pack generates a JS file which contains an init() function that contains at the beginning:

if (typeof input === 'undefined') {
    input = new URL('crate_name_bg.wasm', import.meta.url);

The workaround is to provide the path directly, like I do here:

System Info


Used Package Manager



No response


Copy link

lukastaegert commented Sep 27, 2021

I can confirm this as I stumbled across this myself, but I would suggest to just use location, which is equivalent to window.location in the browser and self.location in the worker. My workaround was to write self.window = {location: self.location} in the web worker code, which feels wrong.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

Successfully merging a pull request may close this issue.

3 participants