Vite - shared worker is impoperly bundled #17674
Replies: 1 comment
-
The |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a shared worker that I define as:
new SharedWorker(new URL(window.location.origin + window.location.pathname + 'src/foo/bar.js'), {type: "module"})
This was the only way it worker properly in development. But when I build the app and try it in production, the worker is not being loaded.
Chrome-based browser will print
Failed to fetch a worker script.
in console, firefox won't show anything.I checked into the bundled js, the code for the worker is there, so it is bundled, but I have also noticed that the code is exactly the same as above. Which means, in production, the script is being "imported" from the
window.location.origin + window.location.pathname + "src/foo/bar.js"
, which does not exist, so it fails. That means Vite is not recognizing the path and adjusting it to the bundled output.I am also bundling all js and css into single file, so there is nothing to import. But there is missing proper reference to the imported worker, which is a constant.
So how do i fix this? I repeat, the import path was the only way to make it work in development. So I cannot simply do a "is dev or is prod" import switch.
PS: i think the worker must not be bundled because background workers should be dedicated files that are imported by the browser. So that is something i need to fix. But that still does not fix the import path.
Beta Was this translation helpful? Give feedback.
All reactions