Invariant: Missing 'next-action' header #64214
-
This issue is quite hard to reproduce in a sandbox or an implementation as it quite flaky. But within our current application that have around 30k users daily we get this type of errors around 40 time a day: the error itself is: Error: Failed to find Server Action "null". This request might be from an older or newer deployment. Original error: Invariant: Missing 'next-action' header. That been say, there is an already previously closed discussion reporting it (#59105) with quite the amount of comments on it where the currently proposed fix didn't work for most of the cases. I highly suspect that this issue had to do with how nextjs handle middleware and that sometime receive not correctly formated query that nextjs doesn't handle properly. here is the extract of my current middleware were you can see i am indeed depending on the import { Domains } from "..."
import createMiddleware from "next-intl/middleware"
const intlMiddleware = createMiddleware({
locales: Domains?.map(({ defaultLocale }) => defaultLocale),
defaultLocale: "us",
domains: Domains,
localePrefix: "never",
timeZone: "Europe/Madrid"
})
const middleware = req => {
// GET DEFAULT LOCALE
const host = req.headers.get("host")
const { defaultLocale = "us" } = Domains.find(({ domain }) => domain === host)
req.cookies.set("NEXT_LOCALE", defaultLocale)
// APPLY TRANSLATION MIDDLEWARE
return intlMiddleware(req)
}
export default middleware
export const config = {
matcher: ["/", "/((?!api|_next|_vercel|.*\\..*).*)"]
} my infra is the following just in case --> cloudflare CDN --> nginx load balancer --> kubernetes --> docker image of nodejs 20 --> nextjs |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 16 replies
-
I get the same thing from attempts to generate opengraph-images lol |
Beta Was this translation helpful? Give feedback.
-
I got the same issue in simple production environment, my setup is,
|
Beta Was this translation helpful? Give feedback.
-
I got the same in my server action
And happens only on prod I assume based on this line might be related with cookies something but i'm not sure: |
Beta Was this translation helpful? Give feedback.
-
Not getting this exact error but I am getting one mentioned in the previous thread:
Only happens in prod for me, running on AWS ECS, not using server actions and using Next version 14.0.3 |
Beta Was this translation helpful? Give feedback.
-
my middleware looks like this with same problem (for more context)i am using next-auth. the config for next auth is
And my Middleware config is
|
Beta Was this translation helpful? Give feedback.
-
Maybe i could have a potential solution if you had the same case as me. I was until now using the i also added another header: async headers() {
return [
{
source: "/:path*{/}?",
headers: [{ key: "Access-Control-Allow-Origin", value: process.env.NEXT_PUBLIC_HOSTNAME }]
},
{
source: "/:path*{/}?",
headers: [{ key: "X-Accel-Buffering", value: "no" }]
}
]
}, as the x accel buffering that is used by nginx create conflict with the cached queries |
Beta Was this translation helpful? Give feedback.
-
And since @erwanriou have large traffic on daily basis, does this error effect the normal functioning of your app ? I wrote the app for another person, and he never complained about usability, and this error continues in the server log. |
Beta Was this translation helpful? Give feedback.
-
What type are your pages @erwanriou? Are you using |
Beta Was this translation helpful? Give feedback.
-
Hi! Can you all try the latest canary version? This issue should be fixed with #64315. |
Beta Was this translation helpful? Give feedback.
-
So what leads to these requests? Where are these 404s coming from |
Beta Was this translation helpful? Give feedback.
-
I don't use any server actions and get these errors all the time. They are seemingly random and without any further info about the requests in the error logs. Using next@14.2.4. |
Beta Was this translation helpful? Give feedback.
Hi! Can you all try the latest canary version? This issue should be fixed with #64315.