-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Description
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.href) 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
Steps to reproduce
- open https://stackblitz.com/https://github.com/hi-ogawa/reproductions/tree/main/vite-16103-new-url-worker-self-reference-build
- run
pnpm build
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/[email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:47541:11)
at workerFileToUrl (file:///home/projects/zzmivvkwxy.github/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:47622:31)
at Object.transform (file:///home/projects/zzmivvkwxy.github/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:48057:32)
at eval (file:///home/projects/zzmivvkwxy.github/node_modules/.pnpm/[email protected]/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.0Used Package Manager
pnpm
Logs
No response
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.