nextjs - 💡(How to fix) Fix next-env.d.ts toggles between .next/dev/types/routes.d.ts and .next/types/routes.d.ts even with typedRoutes: false [7 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#86001Fetched 2026-04-08 02:13:06
View on GitHub
Comments
7
Participants
4
Timeline
19
Reactions
9
Timeline (top)
commented ×7subscribed ×7labeled ×2closed ×1

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.15.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.12.0
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: 15.2.0
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.6.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/marcinincreo/next-typedroutes-toggle-repro

To Reproduce

  1. Start application
  2. Run dev script
  3. This will add import "./.next/dev/types/routes.d.ts"; to next-env.d.ts file
  4. Run build script
  5. This will add import "./.next/types/routes.d.ts"; to next-env.d.ts file

Current vs. Expected behavior

Expected Behavior

  • When typedRoutes: false, next-env.d.ts should not include any import "./.next/.../types/routes.d.ts" line.
  • The file should remain stable between dev and build runs.

Actual Behavior

  • The file keeps toggling between the dev and prod paths.
  • The import line is added even when typedRoutes is disabled.
  • This results in persistent Git changes and noise in commits.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 22.15.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.12.0
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: 15.2.0
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.6.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

TypeScript

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

No response

extent analysis

TL;DR

  • The issue can be mitigated by ensuring that the next-env.d.ts file is not modified unnecessarily during dev and build runs, potentially by adjusting the script that adds imports to this file.

Guidance

  • Review the dev and build scripts to understand why import "./.next/dev/types/routes.d.ts"; and import "./.next/types/routes.d.ts"; are being added to next-env.d.ts even when typedRoutes is disabled.
  • Consider adding a conditional statement to these scripts to only add the import lines when typedRoutes is enabled.
  • Investigate if there's a configuration option in Next.js or TypeScript that can prevent unnecessary modifications to the next-env.d.ts file.
  • Verify that the typedRoutes option is correctly set to false in the Next.js configuration when running the dev and build scripts.

Example

No specific code example can be provided without knowing the exact scripts or configurations used, but the adjustment might look something like this:

if (typedRoutes) {
  // Add import lines to next-env.d.ts
}

Notes

  • The exact solution depends on the specifics of the scripts and configurations used, which are not fully detailed in the issue.
  • It's also possible that this behavior is a result of a version-specific issue with Next.js or TypeScript, but without more information, it's difficult to say for certain.

Recommendation

  • Apply workaround: Adjust the scripts to conditionally add import lines based on the typedRoutes option to prevent unnecessary modifications to next-env.d.ts. This approach is recommended because it directly addresses the observed behavior without requiring upgrades or changes to dependencies that might introduce other issues.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING