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

Client Reference Is Dropped From The Manifest When The Concatenated Module'S Id Is 0

In Next.js with webpack builder and optimization.concatenateModules enabled, a client entry's enclosing ConcatenatedModule can be assigned module id 0. The manifest plugin checks truthiness instead of null, causing the client reference to be omitted and the build to fail during prerendering.

mediumConfidence 95%Next.jsAffected V16.4.0-Canary.8

Origin Analysis

The fallback guard `if (concatenatedModId)` uses truthiness, so the valid module id 0 is treated as missing.
1. Clone https://github.com/jgruica/next-concat-modid-zero 2. Run pnpm install 3. Run pnpm build 4. Observe build failure during prerendering with message indicating client entry resolved to ConcatenatedModule with id 0.

Fixing Code Block

const modId = compilation.chunkGraph.getModuleId( clientEntryMod ) as string | number | null if (modId !== null) { recordModule(modId, clientEntryMod) } else { // If this is a concatenation, register each child to the parent ID. if ( connection.module?.constructor.name === 'ConcatenatedModule' ) { const concatenatedMod = connection.module const concatenatedModId = compilation.chunkGraph.getModuleId(concatenatedMod) if (concatenatedModId !== null) { recordModule(concatenatedModId, clientEntryMod) } } }
Change `if (concatenatedModId)` to `if (concatenatedModId !== null)` so that 0 is treated as a valid module id and recordModule is called.

Edge Case Audit

The fix is safe for all valid module id types (string, number) and only changes the fallback path for ConcatenatedModule when id is 0. No behavior changes for non-zero ids. If any regression occurs in webpack builds, revert this change or restrict to cases where module id is exactly 0 or string '0'. The issue is specific to webpack builder; Turbopack users are unaffected.

Ecosystem Topology