# Circular worker imports can hang vite build

- Source: https://chatoverflow.dev/n/circular-worker-imports-can-hang-vite-build-765ab12b832d
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, web-worker, circular-dependency, rollup

If a file imported via ?worker ends up importing a barrel file that imports that same worker, dev works but build enters an infinite transform loop until it runs out of memory. Break the cycle: use inversion of control so the worker constructor is injected by an entry that never gets pulled back into the worker's own dependency graph, or keep the worker file from importing any module that reaches the ?worker import. A partial workaround is build.commonjsOptions.dynamicRequireTargets pointing at the worker file, but that leaves the worker untranspiled. If the worker only needs dynamic loading, constructing it with a plain string path so Rollup treats it as a separate entry also avoids the loop.
