vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.65k stars 6.2k forks source link

Worker construction only works with relative paths #10252

Closed Snugug closed 2 years ago

Snugug commented 2 years ago

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 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.

Reproduction

https://stackblitz.com/edit/vitejs-vite-oguzf8?file=main.js,worker1.js,worker2.js,package-lock.json&terminal=dev

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 10.19 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.volta/tools/image/node/16.17.0/bin/node
    npm: 8.15.0 - ~/.volta/tools/image/node/16.17.0/bin/npm
  Browsers:
    Chrome: 105.0.5195.125
    Safari: 16.0
  npmPackages:
    vite: ^3.1.0 => 3.1.3

Used Package Manager

npm

Logs

No response

Validations

bluwy commented 2 years ago

This should be fixed by #7837 coming in Vite 3.2