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

Next/Root-Params Typegen Emits Invalid TypeScript For Hyphenated Root Param Segments

Next.js 16.3.x generates `.next/types/root-params.d.ts` with an export function named after the raw param segment. When the segment name is not a valid JS identifier (e.g. `[lang-country]`), the emitted `export function lang-country()` is a TypeScript syntax error, causing `next build` to fail during type checking with no user-side workaround.

highConfidence 95%Next.jsAffected V16.3.0Affected V16.3.1Affected V16.3.2Affected V16.3.3Affected Vcanary

Origin Analysis

`generateRootParamsTypes` in `packages/next/src/server/lib/router-utils/root-params-type-utils.ts` interpolates the param name directly into `export function ${paramName}()` without validating that it is a valid JavaScript identifier. Hyphenated dynamic segments are legal in the file system router, but the generated declaration becomes invalid TypeScript.
1. Create a root dynamic segment whose folder name is not a valid identifier, e.g. `app/[lang-country]/layout.tsx` (root layout inside the segment). 2. Run `next build`. 3. The build fails during type checking with `TS1005` errors in `.next/types/root-params.d.ts`.

Fixing Code Block

Edge Case Audit

This patch relies on string module export names available since TypeScript 4.5; Next.js 16 already requires a newer TypeScript, so this is safe. If future changes introduce param names containing `"` or `\`, the string export name must be escaped to avoid another syntax error. The change only affects generated `.d.ts` files and has no runtime impact. Rollback is straightforward: revert the type-utils change; until then, users can patch locally or stay on 16.2.x if hyphenated root params are critical.

Ecosystem Topology