AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack Dynamic Worker Path Includes TypeScript Declaration Files Causing Build Failure

When a dynamic new Worker() path is used, Turbopack expands the directory context to include all files, including .d.ts, .d.cts, and .d.mts declaration files, which cannot be loaded at runtime. This leads to 'Unknown module type' or module format mismatch errors and breaks builds.

highConfidence 85%Next.jsAffected V16.3.7Affected V16.4.0-Canary.52

Origin Analysis

Turbopack's dynamic import/worker asset resolution lacks filtering for TypeScript declaration files, which are type-only and never valid runtime modules. The context module expansion treats them as runtime assets and attempts to compile them, failing because they have no associated runtime module type.
1. Clone https://github.com/orleib-lab/turbopack-dcts-worker-repro\n2. Run npm install\n3. Run npm run build\n4. Build fails with error on node_modules/worker-pkg/dist/index.d.cts

Fixing Code Block

Edge Case Audit

This change should be safe as declaration files cannot be executed at runtime; however, any tooling that relied on Turbopack mistakenly including them would break (none expected). Rollback: revert the filtering patch. Additionally, ensure the filter is applied consistently in both bundled and external tracing paths to avoid divergent behavior.

Ecosystem Topology