You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i have created a default, vite template svelte (with typescript) and i am trying to import a Worker (from src/lib/worker.js, that imports code from both a local file (src/lib/test.ts) and a local dependency ("comlink"). in dev mode it works fine but after building and running it using a static file server (for example sirv-cli) it silently fails (i.e. just doesn't execute). if i remove the imports to local files (like i have in the fix branch) it works again.
note: since this i have only tested this with svelte configuration (both regular vite svelte and svelte-kit) the issue might come from the svelte plugin for vite (@sveltejs/vite-plugin-svelte), but since the transpiling is done by vite i suspect the issue comes from here
if you see two console logs, one labeled as "App.svelte" and one labeled as "worker.js", then it's working.
if you only see the "App.svelte" console log then the web worker is not working
broken
$ git switch main
$ npm install
$ npm run build
$ npx sirv-cli dist
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Currently Vite doesn't bundle files imported with ?url and simply treats as a simple asset.
A workaround is to use: new Worker(new URL('./worker.js', import.meta.url), { type: "module" }) (docs).
thank you so much, i do think it should be explicitly stated in the docs that imports like that don't actually get bundled.
i didn't think to use the new URL method, since that threw a build error on my production build (and i forgot to test in the reproduction) but that seems to be the fault of sveltejs/kit#9528.
Describe the bug
i have created a default, vite template svelte (with typescript) and i am trying to import a
Worker
(fromsrc/lib/worker.js
, that imports code from both a local file (src/lib/test.ts
) and a local dependency ("comlink"
). in dev mode it works fine but after building and running it using a static file server (for example sirv-cli) it silently fails (i.e. just doesn't execute). if i remove the imports to local files (like i have in thefix
branch) it works again.note: since this i have only tested this with svelte configuration (both regular vite svelte and svelte-kit) the issue might come from the svelte plugin for vite (
@sveltejs/vite-plugin-svelte
), but since the transpiling is done by vite i suspect the issue comes from hereReproduction
https://github.com/m4rch3n1ng/vite-webworker-bug-reproduction
Steps to reproduce
info
if you see two console logs, one labeled as
"App.svelte"
and one labeled as"worker.js"
, then it's working.if you only see the
"App.svelte"
console log then the web worker is not workingbroken
works in dev mode
fix (annoying and non-optimal)
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: