nextjs - 💡(How to fix) Fix Proxy file build error: “Route segment config is not allowed in Proxy file at './proxy.ts'” with no config export 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#87120Fetched 2026-04-08 02:07:47
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
closed ×1commented ×1issue_type_added ×1labeled ×1

Error Message

I am experiencing a persistent build error with Next.js 16.x (tried 16.0.10 and 16.0.8): Error: Route segment config is not allowed in Proxy file at "./proxy.ts". Proxy always runs on Node.js runtime. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy Here’s a ready-to-use template for your GitHub issue to report the persistent proxy.ts build error to the Next.js team: Build fails with the above error, even after all cleanups and version changes. error occured at npm run build

Code Example

OS windows 11
visual studio code
next and node js
postgres

error occured at npm run build
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/vercel/next.js/issues

To Reproduce

I am experiencing a persistent build error with Next.js 16.x (tried 16.0.10 and 16.0.8):

My proxy.ts file does not contain any export const config or similar config export. I have only one proxy.ts in my project root, and no proxy.js or middleware.ts files.

Error: Route segment config is not allowed in Proxy file at "./proxy.ts". Proxy always runs on Node.js runtime. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy

proxy.ts:

import { auth } from "@/auth"; import { NextResponse } from "next/server";

export const runtime = "nodejs";

const publicRoutes = [ "/", "/products", "/auth/login", "/auth/register", "/auth/forgot-password", "/auth/reset-password", "/auth/verify-email", "/admin/login", "/user/login", ];

export default auth(async (req) => { const { nextUrl } = req; const isLoggedIn = !!req.auth; const userRole = req.auth?.user?.role as string | undefined; const userId = req.auth?.user?.id;

const isApiAuthRoute = nextUrl.pathname.startsWith("/api/auth"); const isAuthRoute = nextUrl.pathname.startsWith("/auth"); const isAdminRoute = nextUrl.pathname.startsWith("/admin"); const isUserRoute = nextUrl.pathname.startsWith("/user"); const isProtectedRoute = nextUrl.pathname.startsWith("/account") || nextUrl.pathname.startsWith("/orders") || nextUrl.pathname.startsWith("/checkout") || nextUrl.pathname.startsWith("/wishlist");

if (isApiAuthRoute || publicRoutes.includes(nextUrl.pathname)) { return NextResponse.next(); }

// ...rest of logic... return NextResponse.next(); });

Used 1 reference Here’s a ready-to-use template for your GitHub issue to report the persistent proxy.ts build error to the Next.js team:

Current vs. Expected behavior

What I’ve tried:

Removed all config exports from proxy.ts Ensured only one proxy.ts exists in the project root Deleted .next, node_modules, and package-lock.json, then reinstalled everything Tried both Next.js 16.0.10 and 16.0.8 Restarted my IDE and checked for hidden files No proxy.js or middleware.ts present Expected behavior: The build should succeed since there is no config export in proxy.ts.

Actual behavior: Build fails with the above error, even after all cleanups and version changes.

Steps to reproduce:

Use the above proxy.ts in a Next.js 16.x project Run npm run build Environment:

Next.js version: 16.0.10 (also tried 16.0.8) Node.js version: (your version here) OS: (your OS here) Deployment: Local and Render

Steps to reproduce:

Use the above proxy.ts in a Next.js 16.x project Run npm run build Environment:

Next.js version: 16.0.10 (also tried 16.0.8) Node.js version: (your version here) OS: (your OS here) Deployment: Local and Render

Provide environment information

OS windows 11
visual studio code
next and node js
postgres

error occured at npm run build

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

Not sure

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

Other (Deployed)

Additional context

Steps to reproduce:

Use the above proxy.ts in a Next.js 16.x project Run npm run build Environment:

Next.js version: 16.0.10 (also tried 16.0.8) Node.js version: (your version here) OS: (your OS here) Deployment: Local and Render

extent analysis

TL;DR

The build error is likely due to the proxy.ts file containing route segment config, which is not allowed in proxy files, and the solution involves refactoring the proxy.ts to comply with Next.js requirements.

Guidance

  • Review the proxy.ts file and identify any route segment config that may be causing the issue.
  • Refactor the proxy.ts file to use middleware instead of proxy, as suggested in the error message, by moving the logic to a middleware.ts file.
  • Ensure that the middleware.ts file is properly configured and exported to handle the routes.
  • Verify that the next.config.js file is correctly set up to use the middleware.

Example

// middleware.ts
import { NextResponse } from "next/server";
import { auth } from "@/auth";

export default auth(async (req) => {
  // logic from proxy.ts
});

Notes

The error message suggests that the issue is due to the proxy.ts file containing route segment config, which is not allowed. Refactoring the proxy.ts file to use middleware instead should resolve the issue. However, without more information about the specific requirements of the project, it's difficult to provide a more detailed solution.

Recommendation

Apply workaround: Refactor the proxy.ts file to use middleware instead of proxy, as suggested in the error message. This should resolve the build error and allow the project to be deployed successfully.

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 file build error: “Route segment config is not allowed in Proxy file at './proxy.ts'” with no config export present [1 comments, 2 participants]