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

Turbopack SWC Plugin Configuration Mismatch After Persistent Cache Restore

When multiple SWC plugins are configured and Turbopack's persistent file system cache is enabled (default since Next.js 16.3.0), a restored cache can pair plugin modules with the wrong configuration objects, causing SWC plugin panics and build/dev failures.

highConfidence 90%Next.jsAffected V16.3.0Affected V16.4.0-Canary.43

Origin Analysis

get_swc_ecma_transform_rule_impl creates SwcPluginModule instances concurrently using try_flat_join and stores them via resolved_cell(). Because SwcPluginModule is marked serialization = "skip", the persistent cache does not store the module content. Upon cache restore the task is re-run to refill cells, but the cell indices are assigned based on the order in which concurrent futures complete, which is non-deterministic. The persisted (module cell, config) pairs are then zipped by index, leading to plugins receiving the wrong configuration.
1. Configure multiple SWC plugins in next.config.ts under experimental.swcPlugins.\n2. Ensure Turbopack persistent cache is enabled (default in Next.js 16.3+).\n3. Run `next build` to populate the cache.\n4. Modify any component file to invalidate the cache.\n5. Run `next build` again or restart `next dev`; observe SWC plugin errors such as '@swc-contrib/plugin-graphql-codegen-client-preset receiving configuration from @swc/plugin-formatjs'.

Fixing Code Block

Edge Case Audit

Sequential creation removes parallelism and may slightly increase build times for projects with many SWC plugins. This hotfix addresses the ordering issue but does not add content-addressable persistence for plugin modules; if concurrent execution is reintroduced, the bug may reappear. Rollback: revert this patch and/or set turbopackFileSystemCacheForBuild and turbopackFileSystemCacheForDev to false in next.config.ts. Before deploying, test with multiple plugin configurations and repeated cache restores.

Ecosystem Topology