Describe the bug
I'm building a npm library in vite and import it in another vite project. When using
const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' })
in the library, then the application fails to find the worker with an error in the web console similar to:
Loading Worker from “http://localhost:5173/node_modules/.vite/deps/assets/worker-C5kO0cPB.js” was blocked because of a disallowed MIME type (“”).
Because of the dependency optimization the library gets moved to .vite/deps, but the worker doesn't.
This happens because /* @vite-ignore */ gets added to the import URL when importing the worker via URL, which is correct for an application, but not for a library and especially when using relative paths.
Reproduction
https://github.com/RSWilli/vite-worker-import-bug-repro
Steps to reproduce
See the linked reproduction for more info.
- cd application
- npm run dev
- open in browser, should see two messages from workers
System Info
System:
OS: Linux 6.18 cpe:/o:nixos:nixos:26.05 26.05 (Yarara)
CPU: (16) x64 AMD Ryzen AI 7 PRO 350 w/ Radeon 860M
Memory: 16.06 GB / 30.53 GB
Container: Yes
Shell: 5.3.3 - /nix/store/hkbylipx1iiawqdcjv858p501wv81bpm-bash-interactive-5.3p3/bin/bash
Binaries:
Node: 24.12.0 - /nix/store/cikdc61gfwvdma6y0p9b5d5d448aqcv6-nodejs-24.12.0/bin/node
npm: 11.6.2 - /nix/store/cikdc61gfwvdma6y0p9b5d5d448aqcv6-nodejs-24.12.0/bin/npm
Browsers:
Chromium: 143.0.7499.192
Firefox: 146.0.1
Firefox Developer Edition: 146.0.1
Used Package Manager
npm
Logs
No response
Validations
Describe the bug
I'm building a npm library in vite and import it in another vite project. When using
in the library, then the application fails to find the worker with an error in the web console similar to:
Because of the dependency optimization the library gets moved to .vite/deps, but the worker doesn't.
This happens because
/* @vite-ignore */gets added to the import URL when importing the worker via URL, which is correct for an application, but not for a library and especially when using relative paths.Reproduction
https://github.com/RSWilli/vite-worker-import-bug-repro
Steps to reproduce
See the linked reproduction for more info.
System Info
System: OS: Linux 6.18 cpe:/o:nixos:nixos:26.05 26.05 (Yarara) CPU: (16) x64 AMD Ryzen AI 7 PRO 350 w/ Radeon 860M Memory: 16.06 GB / 30.53 GB Container: Yes Shell: 5.3.3 - /nix/store/hkbylipx1iiawqdcjv858p501wv81bpm-bash-interactive-5.3p3/bin/bash Binaries: Node: 24.12.0 - /nix/store/cikdc61gfwvdma6y0p9b5d5d448aqcv6-nodejs-24.12.0/bin/node npm: 11.6.2 - /nix/store/cikdc61gfwvdma6y0p9b5d5d448aqcv6-nodejs-24.12.0/bin/npm Browsers: Chromium: 143.0.7499.192 Firefox: 146.0.1 Firefox Developer Edition: 146.0.1Used Package Manager
npm
Logs
No response
Validations