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

Minifier Inlines Comma-Assigned Helper Arrow Causing SyntaxError: Identifier 'B' Has Already Been Declared

A syntax error occurs during Next.js build when a module uses a comma-separated variable declaration followed by arrow function assignments. The minifier's variable mangling renames variables in a way that causes a duplicate identifier declaration, breaking the build. The issue can be temporarily resolved by disabling mangling.

highConfidence 85%Next.jsAffected V16.3.1

Origin Analysis

The SWC minifier (or underlying minifier) incorrectly handles a comma expression that assigns arrow functions to previously declared variables. During the inlining and mangling phase, it reuses the same short identifier (e.g., 'b') for different variables within the same scope, resulting in a duplicate declaration SyntaxError.
1. Create a new Next.js app using `npx create-next-app@latest my-app --yes`. 2. Create a file `repro.js` in the root with the exact code provided in the issue (var join, run; join = (e, t) => e + t, run = (rows) => { rows.map((s) => join(s.g, s.r)); return rows.map((s) => (i) => join(s.g, i.l)); }; export { run };). 3. Import the module in `app/page.tsx` as shown. 4. Run `npm run build`. 5. Observe the ChunkLoadError with SyntaxError: Identifier 'b' has already been declared.

Fixing Code Block

Edge Case Audit

Disabling mangling increases the size of the generated JavaScript bundles because variable names are not shortened. The `experimental.swcMinifyDebugOptions` API is experimental and may change or be removed in future Next.js releases, so this fix should be re-evaluated after upgrading. If the issue persists or new errors appear, rollback by removing this config and using the CLI flag `--no-mangling` or pinning to a Next.js version that includes the fix. Concurrency and cross-platform behavior should be unaffected, but always test the build on your specific environment.

Ecosystem Topology