nextjs - 💡(How to fix) Fix Middleware not triggered with node runtime + basePath [1 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#83939Fetched 2026-04-08 02:21:06
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
issue_type_added ×1labeled ×1subscribed ×1

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:28:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 12
Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: 10.4.1
Relevant Packages:
  next: 15.6.0-canary.10 // There is a newer canary version (15.6.0-canary.12) available, please upgrade! 
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.9.2
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/ddaoxuan/node-middleware-matcher

To Reproduce

  1. Clone this repo
  2. Deploy to Vercel
  3. Navigate to /us or any other route that starts with '/us' (basePath config)
  4. Check vercel logs - no middleware logs appear
  5. Page should be rewritten to /us/proxy - actual internal route is used

Current vs. Expected behavior

Current: Middleware is excluded from the request lifecycle Expected: Middleware should be executed

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:28:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 12
Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: 10.4.1
Relevant Packages:
  next: 15.6.0-canary.10 // There is a newer canary version (15.6.0-canary.12) available, please upgrade! 
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.9.2
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)

Vercel (Deployed)

Additional context

Works fine on local, breaks upon vercel deployment

extent analysis

TL;DR

The issue can likely be resolved by updating the Next.js configuration to correctly handle middleware execution on Vercel.

Guidance

  • Verify that the basePath configuration is correctly set in the Next.js config file, as this might affect how middleware is executed.
  • Check the Vercel documentation for any specific requirements or restrictions on using middleware with Next.js, as the issue only occurs on Vercel deployment.
  • Consider upgrading to the latest canary version of Next.js (15.6.0-canary.12) as suggested in the environment information, although this is not directly implied as the solution.
  • Review the middleware code and configuration to ensure it is correctly set up to handle requests starting with the /us path.

Example

No specific code example can be provided without more details on the middleware implementation.

Notes

The issue seems to be related to the deployment on Vercel, as it works fine locally. This suggests that the problem might be related to the specific configuration or environment of Vercel.

Recommendation

Apply workaround: Since the issue is specific to Vercel deployment and the exact cause is not clear, trying to adjust the Next.js configuration or middleware setup to accommodate Vercel's requirements might be the most straightforward approach. Upgrading Next.js to the latest canary version could also be considered, but its direct impact on this issue is uncertain.

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