nextjs - 💡(How to fix) Fix Next 16.2.4: valid app routes return 404 in `next dev` when `src/proxy.ts` is present [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#92921Fetched 2026-04-17 08:25:35
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

On macOS arm64 with Next.js 16.2.4, a fresh App Router project serves valid routes normally in next dev until a root src/proxy.ts file is added.

After adding a no-op proxy.ts, valid app routes like /login return 404 in development, while the same project still works under next build && next start.

Error Message

The same machine also emits Watchpack Error (watcher): Error: EMFILE: too many open files, watch during next dev, but this route-level 404 repro is independent enough to reproduce in a fresh app with only the files above.

Root Cause

On macOS arm64 with Next.js 16.2.4, a fresh App Router project serves valid routes normally in next dev until a root src/proxy.ts file is added.

After adding a no-op proxy.ts, valid app routes like /login return 404 in development, while the same project still works under next build && next start.

Code Example

npx create-next-app@latest next-dev-repro --ts --tailwind --app --src-dir --import-alias "@/*" --use-npm --yes
cd next-dev-repro

---

import { NextResponse, type NextRequest } from "next/server";

export function proxy(request: NextRequest) {
  return NextResponse.next({ request });
}

export const config = {
  matcher: [
    "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
  ],
};

---

export default function LoginPage() {
  return <div>login ok</div>;
}

---

npm run dev

---

HEAD / 200 in 389ms (next.js: 87ms, proxy.ts: 165ms, application-code: 136ms)
HEAD /login 404 in 181ms (next.js: 121ms, proxy.ts: 4ms, application-code: 57ms)
GET /login 404 in 594ms (next.js: 381ms, proxy.ts: 165ms, application-code: 48ms)
RAW_BUFFERClick to expand / collapse

Description

On macOS arm64 with Next.js 16.2.4, a fresh App Router project serves valid routes normally in next dev until a root src/proxy.ts file is added.

After adding a no-op proxy.ts, valid app routes like /login return 404 in development, while the same project still works under next build && next start.

Reproduction

  1. Create a fresh app:
npx create-next-app@latest next-dev-repro --ts --tailwind --app --src-dir --import-alias "@/*" --use-npm --yes
cd next-dev-repro
  1. Add src/proxy.ts:
import { NextResponse, type NextRequest } from "next/server";

export function proxy(request: NextRequest) {
  return NextResponse.next({ request });
}

export const config = {
  matcher: [
    "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
  ],
};
  1. Add src/app/login/page.tsx:
export default function LoginPage() {
  return <div>login ok</div>;
}
  1. Run:
npm run dev
  1. Request /login.

Current behavior

  • GET /login returns 404 Not Found in next dev
  • HEAD /login also returns 404 Not Found
  • server log shows proxy.ts did execute for /login
  • the default / route still returns 200
  • next build && next start serves /login correctly

Observed dev log:

HEAD / 200 in 389ms (next.js: 87ms, proxy.ts: 165ms, application-code: 136ms)
HEAD /login 404 in 181ms (next.js: 121ms, proxy.ts: 4ms, application-code: 57ms)
GET /login 404 in 594ms (next.js: 381ms, proxy.ts: 165ms, application-code: 48ms)

Expected behavior

A no-op src/proxy.ts should not make valid app routes return 404 in development.

Environment

  • Next.js: 16.2.4
  • React: 19.2.4
  • Node: 24.7.0
  • npm: 11.6.2
  • OS: macOS arm64 (Darwin 25.3.0)

Additional context

The same machine also emits Watchpack Error (watcher): Error: EMFILE: too many open files, watch during next dev, but this route-level 404 repro is independent enough to reproduce in a fresh app with only the files above.

extent analysis

TL;DR

The issue can be resolved by adjusting the matcher configuration in the proxy.ts file to correctly handle route matching.

Guidance

  • Review the matcher configuration in proxy.ts to ensure it is correctly set up to handle the desired routes.
  • Verify that the proxy.ts file is not interfering with the default routing behavior of Next.js.
  • Check the server logs to confirm that the proxy.ts file is being executed for the desired routes.
  • Consider adjusting the matcher configuration to use a more specific pattern to avoid interfering with the default routing behavior.

Example

export const config = {
  matcher: [
    "/:path*(svg|png|jpg|jpeg|gif|webp)$", // exclude static assets
    "/_next/:path*", // exclude next.js internal routes
    "/:path*",
  ],
};

Note: This example is a possible solution, but the actual fix may depend on the specific requirements of the application.

Notes

The issue seems to be related to the proxy.ts file interfering with the default routing behavior of Next.js. The matcher configuration may need to be adjusted to correctly handle the desired routes. Additionally, the Watchpack Error mentioned in the additional context may be a separate issue that needs to be addressed.

Recommendation

Apply workaround: Adjust the matcher configuration in the proxy.ts file to correctly handle route matching, as shown in the example above. This should resolve the issue with valid app routes returning 404 in development.

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…

FAQ

Expected behavior

A no-op src/proxy.ts should not make valid app routes return 404 in development.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Next 16.2.4: valid app routes return 404 in `next dev` when `src/proxy.ts` is present [1 comments, 2 participants]