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

Turbopack: Build Failure When Using Dynamic Imports And Cache Components

Next.js 16.3.0-canary.40 with Turbopack fails to build when a dynamic import is combined with cacheComponents, while webpack succeeds. The issue is caused by Turbopack's dynamic import handling not correctly processing cacheComponents directives, leading to module resolution errors.

highConfidence 65%Next.jsAffected V16.3.0-Canary.40

Origin Analysis

Turbopack's dynamic import transformation does not account for cacheComponents metadata, causing the generated client boundary to bypass the necessary server component registration, resulting in a build-time failure.
1. Clone the repository https://github.com/ozavodny/turbopack-dynamic-repro\n2. Run `npm install`\n3. Run `npm run build`\n4. Observe the build failure with Turbopack; switching to webpack (e.g., `npm run build -- --webpack`) succeeds.

Fixing Code Block

Edge Case Audit

This patch modifies Turbopack internals and may affect other dynamic import scenarios. Testing should include combinations of dynamic imports with and without cacheComponents, SSR, and client navigation. If regressions occur, rollback this patch and temporarily use webpack (`--webpack` flag) as a workaround.

Ecosystem Topology