nextjs - 💡(How to fix) Fix `proxy` not working with `pageExtensions` in production builds [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#86302Fetched 2026-04-08 02:11:37
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

Code Example

import { NextResponse, NextRequest } from 'next/server';

export default async function proxy(request: NextRequest) {
  let response = NextResponse.next();

  response.headers.set(
    'my-custom-header',
    'hello'
  );

  return response;
}

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:15:09 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: N/A
  pnpm: 9.6.0
Relevant Packages:
  next: 16.0.2 // There is a newer version (16.0.3) available, upgrade recommended! 
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 4.9.5
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/vercel/next.js/tree/canary/examples/with-emotion

To Reproduce

  1. Add pageExtensions config to next.config.js
  2. Create a proxy.ts file with whatever page extension you defined, e.g. proxy.page.ts
  3. Add the following code to the proxy file:
import { NextResponse, NextRequest } from 'next/server';

export default async function proxy(request: NextRequest) {
  let response = NextResponse.next();

  response.headers.set(
    'my-custom-header',
    'hello'
  );

  return response;
}
  1. Run npm run dev
  2. Visit a page and inspect the html response headers
  3. Confirm that my-custom-header: hello is there
  4. Run npm run build
  5. Run npm run start
  6. Visit a page and inspect the html response headers
  7. Confirm that the my-custom-header is not there

Current vs. Expected behavior

proxy is not running when pageExtensions is configured and a production build is ran. Local dev builds are fine.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:15:09 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 14
Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: N/A
  pnpm: 9.6.0
Relevant Packages:
  next: 16.0.2 // There is a newer version (16.0.3) available, upgrade recommended! 
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 4.9.5
Next.js Config:
  output: N/A

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

Middleware

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

next start (local)

Additional context

No response

extent analysis

TL;DR

The issue can likely be resolved by upgrading to the latest version of Next.js, as the current version has a known issue with middleware not running in production builds when pageExtensions is configured.

Guidance

  • Verify that the issue is specific to production builds by checking if the proxy middleware runs correctly in development mode.
  • Check the Next.js documentation for any known issues or changes related to middleware and pageExtensions in version 16.0.2.
  • Consider upgrading to the latest version of Next.js (16.0.3) as recommended in the environment information.
  • Test the proxy middleware with a different configuration or setup to isolate the issue.

Example

No code snippet is provided as the issue is likely related to a version-specific bug or configuration issue.

Notes

The issue may be specific to the combination of Next.js version 16.0.2 and the pageExtensions configuration. Upgrading to the latest version may resolve the issue, but further testing and verification are necessary.

Recommendation

Upgrade to the latest version of Next.js (16.0.3) to potentially resolve the issue, as it is recommended in the environment information and may include fixes for known issues related to middleware and pageExtensions.

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

nextjs - 💡(How to fix) Fix `proxy` not working with `pageExtensions` in production builds [1 comments, 2 participants]