Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails on self reference worker new Worker(new URL(..., import.meta.url)) in dependency #17843

Closed
7 tasks done
hi-ogawa opened this issue Aug 9, 2024 · 0 comments · Fixed by #17846
Closed
7 tasks done
Labels
feat: web workers p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Aug 9, 2024

Describe the bug

related: #16103

I wasn't sure if this case is intended to work or not, but since the same code works inside the user code (as seen in the test cases added in #16103), I thought it's worth raising an issue to confirm.

I noticed this when adding a test case #17837, but the similar pattern is used in https://github.com/gkjohnson/three-mesh-bvh (which is the dependency of https://github.com/gkjohnson/three-gpu-pathtracer) and I confirmed the build is failing in their examples hi-ogawa/three-gpu-pathtracer#1. Self reference happens here https://github.com/gkjohnson/three-mesh-bvh/blob/9718501eee2619f1015fa332d7bddafaf6cf562a/src/workers/parallelMeshBVH.worker.js#L12

Workaround might be to use new Worker(self.location.self) and it seems to work on my reproduction, but not sure if package authors would adopt this in general (also not sure if this is fool proof).

Reproduction

https://github.com/hi-ogawa/reproductions/tree/main/vite-16103-new-url-worker-self-reference-build

Steps to reproduce

 Build failed in 257ms
error during build:
[commonjs--resolver] Circular worker imports detected. Vite does not support it. Import chain: node_modules/.pnpm/file+dep-new-url-worker/node_modules/test-dep-new-url-worker/worker-recursive.js -> node_modules/.pnpm/file+dep-new-url-worker/node_modules/test-dep-new-url-worker/worker-recursive.js
file: /home/projects/zzmivvkwxy.github/node_modules/.pnpm/file+dep-new-url-worker/node_modules/test-dep-new-url-worker/index.js
    at bundleWorkerEntry (file:///home/projects/zzmivvkwxy.github/node_modules/.pnpm/vite@5.4.0/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:47541:11)
    at workerFileToUrl (file:///home/projects/zzmivvkwxy.github/node_modules/.pnpm/vite@5.4.0/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:47622:31)
    at Object.transform (file:///home/projects/zzmivvkwxy.github/node_modules/.pnpm/vite@5.4.0/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:48057:32)
    at eval (file:///home/projects/zzmivvkwxy.github/node_modules/.pnpm/rollup@4.20.0/node_modules/rollup/dist/es/shared/node-entry.js:19917:40)
 ELIFECYCLE  Command failed with exit code 1.

System Info

(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: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^5.4.0 => 5.4.0

Used Package Manager

pnpm

Logs

No response

Validations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: web workers p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants