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

Duplicate Identifier 'PagesPageConfig' When Building A Page Router NextJS Application Without An Pages/Api Route

Building a Next.js Page Router application after running the dev server and deleting the pages/api directory fails with a TypeScript error: Duplicate identifier 'PagesPageConfig'. The issue is caused by stale generated type files in .next/dev/types that are not cleaned up when API routes are removed.

highConfidence 90%Next.jsAffected V16.3.0-Canary.76Affected V16.3.0-Canary.81

Origin Analysis

During development, Next.js generates type declaration files in .next/dev/types/validator.ts, including a type named PagesPageConfig for API routes and pages. When the pages/api folder is deleted after the dev server has run, the old generated types persist. On subsequent build, the validator file contains duplicate PagesPageConfig declarations because the build process does not detect or remove stale entries, leading to a TypeScript compilation failure.
1. Create a new Next.js app with Page Router (no App Router), TypeScript, and src/ directory. 2. Run `npm run dev`, then stop the dev server. 3. Run `npm run build` — build succeeds. 4. Delete the `src/pages/api` folder (or rename it). 5. Run `npm run dev`, then stop the dev server. 6. Run `npm run build` — build fails with Duplicate identifier 'PagesPageConfig'. 7. Delete the `.next` folder and run `npm run build` again — build succeeds.

Fixing Code Block

Edge Case Audit

This script deletes only the generated type files in .next/dev/types, which are safe to remove but will be regenerated on next dev/build. It is not a permanent fix; the underlying bug in Next.js may still cause issues if new route changes are made between dev and build. Rollback: remove the prebuild script or stop using the workaround after upgrading to a patched version of Next.js.

Ecosystem Topology