-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Workers are not imported correctly despite the worker syntax seemingly being correct, works in parcel #11672
Description
Describe the bug
On an existing project that uses parcel, I switched to vite but that results in web workers not working anymore / returning undefined.
Reference issue with the dev verifying that the worker syntax matches vite's expectations:
Vite worker docs, which use the same syntax as the project at hand:
https://vitejs.dev/guide/features.html#import-with-constructors
My best guess is that the bug here is that a worker is used from a sub-sub package (three-gpu-pathtracer uses the worker from three-mesh-bvh) and that somehow doesn't work in vite right now?
Links to the source code to easily follow the chain until the actual worker:
- https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/example/index.js#L682
(identical to the index.js in the repro project) - https://github.com/gkjohnson/three-gpu-pathtracer/blob/main/src/workers/PathTracingSceneWorker.js#LL10C51-L10C51
- https://github.com/gkjohnson/three-mesh-bvh/blob/master/src/workers/GenerateMeshBVHWorker.js#L9
- https://github.com/gkjohnson/three-mesh-bvh/blob/master/src/workers/generateAsync.worker.js
(the actual worker)
Reproduction
Steps to reproduce
Steps to reproduce in the StackBlitz project linked above:
- Run
npm run dev - Note page loads
- Note page stops loading and console logs error
Uncaught (in promise) Error: GenerateMeshBVHWorker: undefined at worker.onerror
Compare behaviour to https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html
Steps to reproduce locally:
- fork https://github.com/gkjohnson/three-gpu-pathtracer
- run
npm install --save-dev vite - in package.json, add
"start-vite": "cd example && vite --host",in scripts - run
npm run start-vite - visit the page
- note loading works fine, then the MeshBVH worker returns undefined and logs to the console:
Uncaught (in promise) Error: GenerateMeshBVHWorker: undefined
System Info
Reproduces on any system I tried on.
On StackBlitz:
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
vite: ^4.0.4 => 4.0.4 Used Package Manager
npm
Logs
Uncaught (in promise) Error: GenerateMeshBVHWorker: undefined at worker.onerror
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.