Replies: 3 comments 2 replies
-
|
✅ Fix 1 — Restrict the middleware matcher more aggressively Your current matcher: matcher: "/((?!api|trpc|_next|_vercel|.\..).*)", This still catches many internal runtime URLs such as: Server Actions endpoints Framework-internal data requests Internal runtime fetches App router route handlers (when path-rewrites occur) A safer matcher recommended by Next and next-intl maintainers is: export const config = { If you are using Server Actions heavily, also exclude them: export const config = { This ensures middleware runs only for actual page requests, not internal fetches. ✅ Fix 2 — Add localeDetection: false (prevents recursive internal fetches) In many setups, Next.js + next-intl ends up calling the middleware twice because of locale detection. Add this to routing.js: export const routing = defineRouting({ defaultLocale: "ko", // Prevents double invocation & internal fetch loops ✅ Fix 3 — Use next-intl v3+ middleware style If you recently upgraded Next.js 14.2+, use the updated middleware API from next-intl: import createMiddleware from 'next-intl/middleware'; export default createMiddleware({ This version automatically avoids most internal fetch paths. ✅ Fix 4 — AWS Elastic Beanstalk specific issue AWS EB often keeps Node processes alive longer and does not apply the same internal request deduping as Vercel. You can verify this by running locally with: NEXT_RUNTIME_LOGGING=1 You will see repeated calls from internal _internal/ paths → those are the ones you must exclude. |
Beta Was this translation helpful? Give feedback.
-
|
✅ 1. How to enable NEXT_RUNTIME_LOGGING locally This is not something added in next.config.js. Local development If you run your app with next dev, use: NEXT_RUNTIME_LOGGING=1 next dev Local production build If you want to simulate AWS: NEXT_RUNTIME_LOGGING=1 node .next/standalone/server.js This will print internal framework logs to your terminal. ✅ 2. How to enable NEXT_RUNTIME_LOGGING on AWS Elastic Beanstalk Go to: AWS Console → Elastic Beanstalk → Your Environment → Configuration → Software → Environment properties Add a new environment variable: Name: NEXT_RUNTIME_LOGGING Click Save and Apply. Elastic Beanstalk will redeploy and your Node logs will now show: internal Next.js fetches Server Action calls middleware-triggered internal requests any loops or repeated runtime requests This is the log source you need to see what’s causing the UND_ERR_HEADERS_TIMEOUT. ✅ 3. About the screenshot you sent (logging: { fetches: … }) That block only logs your own fetch() calls. NEXT_RUNTIME_LOGGING=1 is the one that logs the internal _next, _internal, server actions, and middleware interactions — which is what you need to debug this issue. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, you're absolutely right - NEXT_RUNTIME_LOGGING doesn't exist. I apologize for the incorrect information.
import { NextResponse } from 'next/server'; export function middleware(request: NextRequest) { const response = NextResponse.next(); return response; export const config = {
Go to: EB Console → Your Environment → Logs → Request Logs → Download Full Logs The middleware will log all requests, and the EB logs will show you what's timing out. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
After adding next-intl (middleware) to a Next.js 14 App Router app and deploying to AWS (Elastic Beanstalk), the site runs normally for ~20–30 minutes, then a massive flood of errors appears and CPU usage spikes. Errors are failed to forward action response TypeError: fetch failed with underlying UND_ERR_HEADERS_TIMEOUT. The errors appear rapidly and repeatedly until the instance is overwhelmed.
This started happening only after introducing next-intl / its middleware. I suspect the middleware is interacting badly with Server Actions or internal fetches, causing internal forward/redirect loops or blocked internal fetches that lead to undici header timeouts.
I have checked all my i18n settings.
I have replaced all usePathname, useRouter, Link, redirect from next packages to next-intl navigation.js.
Environment
next-intl request.js
routing.js
middleware.js
Beta Was this translation helpful? Give feedback.
All reactions