nextjs - ✅(Solved) Fix Error Mismatch when using `notFound()` inside proxy. [1 pull requests, 1 comments, 2 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#86609Fetched 2026-04-08 02:10:07
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
1
Participants
Timeline (top)
commented ×1cross-referenced ×1issue_type_added ×1labeled ×1

Error Message

⨯ Error: Next.js navigation API is not allowed to be used in Proxy. at proxy (proxy.ts:5:10) 3 | 4 | export async function proxy(request: NextRequest) {

5 | notFound() | ^ 6 | } 7 | { digest: 'NEXT_HTTP_ERROR_FALLBACK;404' }

Fix Action

Fixed

PR fix notes

PR #86627: Fix error message mismatch for navigation API in Proxy

Description (problem / solution / changelog)

What?

This PR fixes a bug where the client-side error overlay would incorrectly display "Next.js navigation API is not allowed to be used in Pages Router" when a navigation API error (like notFound() or redirect()) occurred within a Proxy or Middleware.

Why?

As reported in issue #86609, when notFound() is called inside a Proxy (e.g., proxy.ts), the server correctly generates an error message stating "Next.js navigation API is not allowed to be used in Proxy.". However, the client-side error handling logic unconditionally overwrote this message with a generic "Pages Router" error if isNextRouterError was true. This misuse of the error overlay confused users by misidentifying the source of the error.

How?

I modified packages/next/src/client/index.tsx to add a check before overwriting the error message. The code now verifies if the existing error message already contains "Middleware" or "Proxy". If it does, the specific, correct error message from the server is preserved.

I also added a regression test in test/development/app-dir/server-navigation-error/server-navigation-error.test.ts and a corresponding fixture test/development/app-dir/server-navigation-error/proxy.ts to verify that errors from proxy.ts are displayed correctly in the overlay.

Fixes #86609

Changed files

  • packages/next/src/client/index.tsx (modified, +9/-1)
  • test/development/app-dir/server-navigation-error/proxy.ts (added, +10/-0)
  • test/development/app-dir/server-navigation-error/server-navigation-error.test.ts (modified, +40/-0)

Code Example

Error: Next.js navigation API is not allowed to be used in Proxy.
    at proxy (proxy.ts:5:10)
  3 |
  4 | export async function proxy(request: NextRequest) {
> 5 |   notFound()
    |           ^
  6 | }
  7 | {
  digest: 'NEXT_HTTP_ERROR_FALLBACK;404'
}

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041
  Available memory (MB): 49152
  Available CPU cores: 14
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.17.1
Relevant Packages:
  next: 16.0.5 // Latest available version is detected (16.0.5).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: N/A
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/madebyfabian/nextjs-error-mismatch-reprod

To Reproduce

  1. Start the application in development
  2. Visit localhost:3000

Current vs. Expected behavior

Current:

Browser Error shows "Next.js navigation API is not allowed to be used in Pages Router." even though we are only using app router in this reproduction. <img width="1067" height="587" alt="Image" src="https://github.com/user-attachments/assets/7b34ab48-15ef-4a3f-85ef-2fb4984903be" />

Console error is correct:

⨯ Error: Next.js navigation API is not allowed to be used in Proxy.
    at proxy (proxy.ts:5:10)
  3 |
  4 | export async function proxy(request: NextRequest) {
> 5 |   notFound()
    |           ^
  6 | }
  7 | {
  digest: 'NEXT_HTTP_ERROR_FALLBACK;404'
}

Expected: The error shown in the browser should be correct and the same shown as in the console.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041
  Available memory (MB): 49152
  Available CPU cores: 14
Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.17.1
Relevant Packages:
  next: 16.0.5 // Latest available version is detected (16.0.5).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: N/A
Next.js Config:
  output: N/A

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

Error Overlay

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

next dev (local)

Additional context

Found the two files where these are defined: Client: https://github.com/vercel/next.js/blob/canary/packages/next/src/client/index.tsx#L933 Proxy: https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/middleware.ts#L45

And the test https://github.com/vercel/next.js/blob/canary/test/development/app-dir/server-navigation-error/server-navigation-error.test.ts

extent analysis

TL;DR

The issue can be resolved by ensuring that the Next.js navigation API is not used in the Pages Router, as it is only allowed in the App Router.

Guidance

  • Review the code to identify where the Next.js navigation API is being used and refactor it to use the App Router instead.
  • Verify that the next version is up-to-date, as the issue might be related to a specific version.
  • Check the proxy.ts file to ensure that the notFound() function is not being called unnecessarily.
  • Investigate the differences between the console error and the browser error to understand why they are not matching.

Example

No code snippet is provided as the issue is more related to the configuration and usage of Next.js rather than a specific code block.

Notes

The issue seems to be specific to the next dev stage and the Error Overlay area. The provided links to the Next.js codebase and test files can be useful in understanding the root cause of the issue.

Recommendation

Apply workaround: The issue can be resolved by refactoring the code to use the App Router instead of the Pages Router for the Next.js navigation API. This is because the error message explicitly states that the Next.js navigation API is not allowed to be used in Pages Router.

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