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

Dev Types For URL-Encoded Underscore Route Segments Conflict With Production Types

After running `next dev`, `tsc` fails with TS2344 because `.next/dev/types/routes.d.ts` uses encoded `%5F` for underscore route segments while `.next/types/routes.d.ts` uses decoded `_`, creating incompatible `LayoutRoutes` unions.

mediumConfidence 85%Next.jsAffected V16.2.6

Origin Analysis

The dev type generator emits URL-encoded path segments (e.g. `%5F`) for route folders while the production type generator emits decoded segments (`_`). This leads to mismatched `LayoutRoutes` types between `.next/dev/types` and `.next/types/routes`. The generated `.next/dev/types/validator.ts` then imports both and fails constraint checks.
1. Start the app in dev mode: `npm run dev` 2. Stop server and run the test script: `npm t` 3. Observe TS2344 errors in `.next/dev/types/validator.ts` related to `LayoutRoutes` and `%5F` vs `_`.

Fixing Code Block

// scripts/clean-next-dev-types.js const fs = require('fs'); const path = require('path'); const dir = path.join(process.cwd(), '.next', 'dev', 'types'); if (fs.existsSync(dir)) { fs.rmSync(dir, { recursive: true, force: true }); console.log('Removed .next/dev/types to avoid dev/prod route type mismatch'); }
This script removes the stale `.next/dev/types` directory before running `tsc`. Since the production types (`.next/types`) are already correct and self-sufficient for type checking, deleting the dev-specific generated types resolves the conflict. Add `node scripts/clean-next-dev-types.js && tsc --noEmit` to your test script.

Edge Case Audit

This is a workaround, not a permanent fix. It must not be run while `next dev` is active, as the dev process may recreate the directory. It also removes dev-specific route type enhancements that may be needed for editor IntelliSense. Rollback: remove the script and restore original `test` command. A proper fix should align dev and prod type generation in Next.js.

Ecosystem Topology