Failed to Find Server Action in Next.js: 3 Causes and the Fix for Each

Seeing "Failed to find Server Action" in your Next.js logs? Read the action ID to tell bot probes, stale browser tabs and a missing shared encryption key apart, then apply the matching fix.

Ask ChatGPTAsk Claude
Failed to find Server Action cover: three causes and the fix for each, with a 32-byte shared build key
On this page
  1. What does "Failed to find Server Action" mean?
  2. How do you tell which cause you have?
  3. How do you fix it across multiple Next.js instances?
  4. How do you stop it after every deploy?
  5. How do you stop bot probes from filling your logs?
  6. What else produces this error?
  7. Key takeaways
  8. FAQ
  9. Is "Failed to find Server Action" a bug in Next.js?
  10. Why do I see it when I don't use Server Actions?
  11. How do I fix it when running several Next.js containers?
  12. Does deploymentId stop the error after a deploy?
  13. How do I generate the encryption key?

Failed to find Server Action means Next.js received a Server Action ID in the right format, but the build that handled the request does not contain that action. The fix depends on what sent the ID: a bot with a made-up value, a browser tab left open across a deploy, or one of several instances that built with its own encryption key. This guide tells the three apart from a single log line and gives the fix for each. Every Next.js setting below comes from the official docs; the proxy rule comes from a community thread.

What does "Failed to find Server Action" mean?#

Next.js gives every Server Action a non-deterministic ID so the client can call it, and the IDs can change between builds. When a request arrives with an ID the current build does not know, Next.js logs the error and rejects the call. The official error page describes two messages:

text
Failed to find Server Action "<id>". This request might be from an older or newer deployment.
Server Reference ID did not match the expected format

The first means the ID looked valid but matched nothing in this build. The second means the ID was not in the format the current Next.js version generates, which the docs attribute to mismatched client and server versions or to malformed requests, including automated scanning traffic.

How do you tell which cause you have?#

Read the action ID in the log line. It tells you the cause faster than any config change will.

Table mapping the action ID in the log to its cause and fix: a short value is a bot, a long ID after a deploy is a stale tab, a long ID on many instances is a key mismatch

The first three rows are the three causes; the fourth is a variant of the same error.

What the log showsLikely causeFix
ID is x or a few charactersBot probesReturn 400 at the proxy
Long hash (40+ characters), right after a deployOld tab, new buildSet a deploymentId
Long hash (40+ characters), several instancesDifferent key per buildOne shared encryption key
"Server Reference ID did not match"Version mismatch or malformed requestAlign versions, filter at the proxy

Reports in the Next.js discussions show the pattern. The original thread, vercel/next.js#58431, starts with a real 40-character ID after a deploy to users who had not refreshed. The later thread, vercel/next.js#87851, is full of apps logging Server Action "x" thousands of times a day, some of them with no Server Actions at all.

How do you fix it across multiple Next.js instances?#

Set one NEXT_SERVER_ACTIONS_ENCRYPTION_KEY at build time and run the same build everywhere. Next.js encrypts Server Action closure variables before sending them to the client, and by default each build generates its own key. Per the self-hosting guide, when several instances use different keys, one cannot decrypt what another encrypted, which causes this exact error.

The key must be base64 with a valid AES length of 16, 24 or 32 bytes. Next.js generates 32-byte keys by default, and the Data Security guide shows how to make one:

bash
openssl rand -base64 32

Four-step flow: generate one 32-byte key, add it as a build variable, run next build, then every container from the image shares it

The variable has to exist at build time because the key is embedded in the build output and used automatically at runtime. In a Docker build that means passing it as a build argument, not only as a runtime environment variable:

dockerfile
# Dockerfile (builder stage)
ARG NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
ARG NEXT_DEPLOYMENT_ID
ENV NEXT_SERVER_ACTIONS_ENCRYPTION_KEY=$NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
ENV NEXT_DEPLOYMENT_ID=$NEXT_DEPLOYMENT_ID
RUN npm run build

On a platform such as Coolify, create the variable once and make it available at build time, so every rebuild reuses the same key. My Dockerfile for Next.js and the Coolify deployment walkthrough cover the rest of that pipeline. Keep the key in your secret store like any other secret.

How do you stop it after every deploy?#

Set a deploymentId so the browser knows when the server it talks to has changed. Per the deploymentId docs, Next.js then appends ?dpl=<id> to static asset URLs, sends an x-deployment-id header on client navigations and, when the server's response reports a different ID, does a full page reload instead of a client-side navigation.

ts
// next.config.ts
import type { NextConfig } from "next"

const config: NextConfig = {
  deploymentId: process.env.DEPLOYMENT_VERSION || process.env.GIT_SHA,
}

export default config

You can also set NEXT_DEPLOYMENT_ID at build time, and a non-empty environment variable wins over the config value. Use a value that changes per release, such as the git SHA, and make sure every instance of the same release gets the same one.

Be realistic about what this buys you. The docs state that Next.js does not read the ?dpl= parameter on incoming requests, and that a per-deployment value only avoids skew if requests are also routed by deployment, which comes from your host or CDN. Because the mismatch is detected from navigation responses, an action fired from a stale tab before any navigation can still fail. To avoid even that, keep the previous container serving until its traffic drains. On Vercel, Skew Protection does this for you.

How do you stop bot probes from filling your logs?#

Reject POST requests with a tiny next-action header at the reverse proxy, before they reach Node. Real action IDs are long hashes, so a value like x is almost certainly a probe. One team in the #87851 thread reports that valid IDs are 40 or more hex characters and that blocking values shorter than 10 characters removed the noise, using a Caddy rule:

text
@malformed_action {
    method POST
    header next-action *
    not {
        header_regexp next-action "^.{10,}$"
    }
}
respond @malformed_action "Bad Request" 400

The same idea in nginx, placed in the http block, with the check inside your location:

nginx
map $http_next_action $malformed_action {
    default 0;
    "~^.{1,9}$" 1;
}

server {
    location / {
        if ($malformed_action) { return 400; }
        proxy_pass http://127.0.0.1:3000;
    }
}

This checks length only, so any future ID format passes through. Also keep the app port off the public internet, so scanners cannot skip the proxy: a Cloudflare Tunnel in front of Docker Compose does that without opening ports.

What else produces this error?#

Four other things can produce it, so check these when the three causes above do not match:

  • Mismatched Next.js versions. The "did not match the expected format" variant appears when client and server run versions with different ID formats. Rebuild so assets and server come from one deployment. If it keeps happening on a single version, the docs say to report it to the Next.js project.
  • Tab state. People in thread #58431 report it after logging out in one tab and calling an action from another, or from an intercepted-route modal.
  • Dev-only bugs. Several 14.0.x dev reports involved Server Actions called from client components. Confirm the problem on a current release before debugging your code.
  • A proxy origin mismatch is a different error. Next.js compares the Origin header with x-forwarded-host, and a proxy that forwards its own host needs an entry in experimental.serverActions.allowedOrigins, as the serverActions docs explain.

If you are weighing whether an action is the right tool at all, see Server Actions vs route handlers. The full path to a stable self-hosted app is in the self-host Next.js guide, and if you want this set up on your own server, I build that as part of Next.js development.

Key takeaways#

  • The error means a well-formed action ID that the receiving build does not contain.
  • Read the ID first: a short value is a bot, a long hash is skew or a key mismatch.
  • Several instances need one NEXT_SERVER_ACTIONS_ENCRYPTION_KEY, set at build time, base64 of 16, 24 or 32 bytes.
  • A deploymentId makes clients reload on a new deployment, but a stale tab can still fail once.
  • Return 400 at the proxy for tiny next-action header values to clean your logs.

FAQ#

Is "Failed to find Server Action" a bug in Next.js?#

Usually not. Next.js received a Server Action ID in the expected format, but the running build has no action with that ID, which means the browser and server are on different builds or the request is a probe with a made-up ID.

Why do I see it when I don't use Server Actions?#

Bots send POST requests with a fake next-action header such as x, and Next.js logs the failed lookup. Threads on the Next.js repository report thousands of these lines a day, including from apps with no Server Actions. Block short header values at the reverse proxy.

How do I fix it when running several Next.js containers?#

Build one image and run it everywhere, and set NEXT_SERVER_ACTIONS_ENCRYPTION_KEY at build time to a base64 value of 16, 24 or 32 bytes. Without it each build generates a key, and another instance cannot decrypt what the first one produced.

Does deploymentId stop the error after a deploy?#

It makes clients detect a new deployment through a response header and reload instead of navigating with stale assets. A stale tab can still fail on its first action, and only routing requests to the matching deployment avoids that, which the Next.js docs say comes from your host or CDN.

How do I generate the encryption key?#

Run openssl rand -base64 32, which the Next.js docs show as an example. Next.js generates 32-byte keys by default, so that length matches.

Questions

Comments

Add to the discussion…

No comments yet. Questions, corrections and your own results are all welcome.

Be kind and stay on topic. No name needed: leave it blank and you post under an anonymous name that stays yours. Links get nofollow; spam is removed. Your email is never shown and is only used for reply notifications you ask for. Privacy