Skip to content

Workers are not imported correctly despite the worker syntax seemingly being correct, works in parcel #11672

@hybridherbst

Description

@hybridherbst

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:

Reproduction

https://stackblitz.com/edit/vitejs-vite-k1ccfw?file=index.js

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions