nextjs - ✅(Solved) Fix proxy.ts does not execute in production when behind Cloudflare Proxy (middleware.ts works) [1 pull requests, 58 comments, 9 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#86122Fetched 2026-04-08 02:12:31
View on GitHub
Comments
58
Participants
9
Timeline
102
Reactions
1
Author
Timeline (top)
commented ×58subscribed ×20mentioned ×11referenced ×5

Fix Action

Fixed

PR fix notes

PR #8218: meta: upgrade to next.js 16

Description (problem / solution / changelog)

This PR is a draft PR for upgrading to Next.js 16.

  • Development Server Works
  • Production Build fails
❯ pnpm build

> @node-core/website@ prebuild /home/cwunder/GitHub/nodejs.org/apps/site
> node --run build:blog-data


> @node-core/website@ build /home/cwunder/GitHub/nodejs.org/apps/site
> node --run build:default -- --turbopack

   ▲ Next.js 16.0.0-beta.0 (Turbopack)
   - Experiments (use with caution):
     ✓ globalNotFound
     · optimizePackageImports
     ✓ parallelServerBuildTraces
     ✓ parallelServerCompiles
     ✓ turbopackFileSystemCacheForDev
     ✓ webpackBuildWorker

   Creating an optimized production build ...
 ✓ Compiled successfully in 5.1s
   Skipping validation of types
 ✓ Collecting page data in 654ms    
Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
Error [PageNotFoundError]: Cannot find module for page: /_document
    at ignore-listed frames {
  code: 'ENOENT'
}
Export encountered an error on /_error: /404, exiting the build.
 ⨯ Next.js build worker exited with code: 1 and signal: null
 ELIFECYCLE  Command failed with exit code 1.

Changed files

  • .prettierignore (modified, +1/-0)
  • apps/site/app/[locale]/error.tsx (modified, +5/-6)
  • apps/site/app/[locale]/not-found.tsx (modified, +1/-5)
  • apps/site/app/global-error.tsx (removed, +0/-34)
  • apps/site/components/withNodeRelease.tsx (modified, +7/-12)
  • apps/site/eslint.config.js (modified, +1/-1)
  • apps/site/next-env.d.ts (modified, +1/-1)
  • apps/site/next.config.mjs (modified, +5/-5)
  • apps/site/open-next.config.ts (modified, +2/-3)
  • apps/site/package.json (modified, +11/-10)
  • apps/site/tsconfig.json (modified, +3/-2)
  • apps/site/turbo.json (modified, +10/-2)
  • package.json (modified, +2/-2)
  • pnpm-lock.yaml (modified, +743/-255)
  • pnpm-workspace.yaml (modified, +2/-1)

Code Example

npx create-next-app@latest

---

// middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(req: NextRequest) {
  console.log("MIDDLEWARE RUNNING:", req.nextUrl.pathname);
  return NextResponse.next();
}

export const config = {
  matcher: ["/(.*)"],
};

---

// proxy.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function proxy(req: NextRequest) {
  console.log("PROXY RUNNING:", req.nextUrl.pathname);
  return NextResponse.next();
}

export const config = {
  matcher: ["/(.*)"],
};

---

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): 24576
  Available CPU cores: 12
Binaries:
  Node: 22.16.0
  npm: 11.4.2
  Yarn: N/A
  pnpm: 10.18.2
Relevant Packages:
  next: 16.0.2-canary.19 // Latest available version is detected (16.0.2-canary.19).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/shivaluma/report-bug-next16-proxy https://github.com/shivaluma/report-bug-next16-proxy/tree/middleware

To Reproduce

To Reproduce

  1. Create a new Next.js project (or use any existing Next.js 16.0.3 project):
npx create-next-app@latest
  1. At the project root, create a file named middleware.ts:
// middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(req: NextRequest) {
  console.log("MIDDLEWARE RUNNING:", req.nextUrl.pathname);
  return NextResponse.next();
}

export const config = {
  matcher: ["/(.*)"],
};
  1. Deploy the project behind Cloudflare Proxy enabled (Cloudflare orange-cloud ON → proxied traffic).

  2. Visit any route (e.g., /). You will see the expected log output: MIDDLEWARE RUNNING: /

  3. Now rename the file from middleware.tsproxy.ts, and update the function name:

// proxy.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function proxy(req: NextRequest) {
  console.log("PROXY RUNNING:", req.nextUrl.pathname);
  return NextResponse.next();
}

export const config = {
  matcher: ["/(.*)"],
};
  1. Remove the old middleware.ts file. Ensure only proxy.ts exists in the project root.

  2. Redeploy behind Cloudflare Proxy enabled.

  3. Visit any route again.


Actual Result

  • No logs appear.
  • The proxy.ts file does not execute at all.
  • Requests behave as if no middleware/proxy file exists.

Expected Result

proxy.ts should execute exactly like middleware.ts, with identical config and behavior, including when Cloudflare Proxy is turned on.

Configuration Usage: output: "standalone"

Current vs. Expected behavior

Current Behavior

  • When using middleware.ts, the middleware executes correctly in:

    • local development (next dev)
    • production
    • production behind Cloudflare Proxy (orange-cloud ON)
  • After renaming the file to proxy.ts and changing the function name accordingly:

    • It still works in local development
    • It still works in production without Cloudflare Proxy
    • But it does NOT execute at all when deployed behind Cloudflare Proxy

There are no logs, no rewrites, no NextResponse behavior, and the file appears to be completely ignored when Cloudflare Proxy is enabled. The only difference between the two scenarios is the file name (middleware.tsproxy.ts).


Expected Behavior

  • According to the deprecation message, proxy.ts should function as a drop-in replacement for middleware.ts.

  • The same logic, same matcher, same runtime, and same root-level file should behave identically.

  • Therefore, proxy.ts should execute in:

    • local development
    • production
    • production behind Cloudflare Proxy just like middleware.ts does.

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): 24576
  Available CPU cores: 12
Binaries:
  Node: 22.16.0
  npm: 11.4.2
  Yarn: N/A
  pnpm: 10.18.2
Relevant Packages:
  next: 16.0.2-canary.19 // Latest available version is detected (16.0.2-canary.19).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone

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

Runtime

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

Other (Deployed)

Additional context

code with proxy.ts: https://github.com/shivaluma/report-bug-next16-proxy code with middleware.ts: https://github.com/shivaluma/report-bug-next16-proxy

production application that running the code with proxy.ts: https://next16-proxy.shiro.fit production application that running the code with middleware.ts: https://next16-middleware.shiro.fit

Visit two website, then open Devtools to see if the cookie "isGuest" successfully set.

extent analysis

TL;DR

The issue can be resolved by using the correct file name middleware.ts instead of proxy.ts for the middleware function, as the deprecation message suggests proxy.ts should be a drop-in replacement, but it's not working as expected with Cloudflare Proxy enabled.

Guidance

  • Verify that the proxy.ts file is correctly configured and deployed, and that the function name and exports match the expected format.
  • Check the Cloudflare Proxy settings to ensure that it's not interfering with the middleware execution.
  • Try renaming the file back to middleware.ts to see if the issue is specific to the file name.
  • Investigate if there are any known issues or limitations with using proxy.ts with Cloudflare Proxy in the Next.js version being used (16.0.3).

Example

No code example is provided as the issue seems to be related to the file name and configuration rather than the code itself.

Notes

The issue might be specific to the combination of Next.js version, Cloudflare Proxy, and the proxy.ts file name. Further investigation is needed to determine the root cause.

Recommendation

Apply workaround: use the middleware.ts file name instead of proxy.ts until the issue is resolved, as it's working correctly with Cloudflare Proxy enabled.

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