-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Description
Describe the bug
I have encountered a bug in Vite when using a worker that calls import, even if the import isn't directly called, and there is a globally defined window variable.
Expected Behavior
The application should run without any errors.
Actual Behavior
An error occurs when the worker is instantiated, even though the import function is not directly called.
Steps to Reproduce
-
Create a new Svelte app using Vite:
pnpm create vite@latest my-app -- --template svelte cd my-app pnpm install -
Create a worker file (
worker.js) that defines a function callingimport:const foo = () => import(url)
-
In the main application file (
App.svelte), import the worker and create a new instance of it:<script> import Worker from './worker.js?worker&inline' new Worker </script>
-
In the Vite configuration file (
vite.config.js), define a globalwindowvariable:export default defineConfig({ plugins: [svelte()], define: { 'window.__DEBUG__': true, }, })
-
Run the application using
pnpm run devand observe the error.
Reproduction
You can find a minimal reproduction of the bug in the following repository:
https://github.com/mustafa0x/vite-worker-bug
You can also find a live reproduction on StackBlitz:
https://stackblitz.com/edit/vitejs-vite-zyhbeh
System Info
Vite version: 6.0.11
@sveltejs/vite-plugin-svelte version: 5.0.3
Svelte version: 5.19.3
Browser: Google Chrome (latest version)
Operating System: macOSUsed Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.