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

Next.Js 16.2.1 Generates Duplicate Type Declarations Causing Conflicts In .Next/Types And .Next/Dev/Types

When running `next typegen` followed by `next dev`, Next.js generates two sets of type declaration files under `.next/types` and `.next/dev/types`. Both directories declare the same TypeScript modules and interfaces (e.g., `next/cache` and `LayoutProps`), causing TS6200 and TS2300 errors when `skipLibCheck` is disabled. This affects users who rely on accurate type checking and may lead to inconsistent type imports.

highConfidence 85%Next.jsApp RouterReact Server ComponentsAffected V16.2.1

Origin Analysis

Next.js's type generation creates separate declaration outputs for build-time (`.next/types`) and dev-time (`.next/dev/types`) without ensuring mutual exclusivity. When both directories exist, TypeScript includes both, and because the generated files use identical ambient module declarations and type aliases, they clash. The issue is exacerbated because `skipLibCheck` is enabled by default, which masks the conflicts.
1. Clone https://github.com/remcohaszing/next-type-error.git 2. Run `npm install` 3. Run `npx next typegen` 4. Run `npx next dev` then stop the server 5. Run `npx tsc` Observe duplicate identifier and module conflict errors.

Fixing Code Block

Edge Case Audit

Enabling `skipLibCheck` may mask other legitimate errors in declaration files. Excluding directories manually may lead to missing type information if the excluded directory is needed (e.g., excluding `.next/dev/types` during development could break dev-specific route types). The `rm -rf` commands are destructive and should be used with caution; ensure you only remove generated files, not source code. Rollback is possible by re-running the respective Next.js command to regenerate the types.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state