When using the new Worker(new URL() web worker construction, using a relative path (i.e../worker.js) will result in the worker being found just fine, but using an absolute path (i.e./worker.js) will result in an error Failed to fetch a worker script., even if both resulted URLs point to the same file. I expect that because the two should resolve to the same file that it would work either way, especially as there is no documentation stating otherwise, but they appear to have different behavior.
[X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
[X] 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.
Describe the bug
When using the
new Worker(new URL()
web worker construction, using a relative path (i.e../worker.js
) will result in the worker being found just fine, but using an absolute path (i.e./worker.js
) will result in an errorFailed to fetch a worker script.
, even if both resulted URLs point to the same file. I expect that because the two should resolve to the same file that it would work either way, especially as there is no documentation stating otherwise, but they appear to have different behavior.Reproduction
https://stackblitz.com/edit/vitejs-vite-oguzf8?file=main.js,worker1.js,worker2.js,package-lock.json&terminal=dev
System Info
Used Package Manager
npm
Logs
No response
Validations