Back to Next Js

Failed to find Server Action

errors/failed-to-find-server-action.mdx

16.2.112.6 KB
Original Source

Why This Message Occurred

For security purposes, Next.js creates non-deterministic IDs that allow the client to reference and call Server Actions. These IDs can change between builds.

You may see one of the following messages:

Failed to find Server Action

This message means that the Server Action ID had the expected format, but no matching Server Action was found in the current build.

This commonly happens when the client and server are using different builds. For example, a browser may still have assets from a previous deployment that reference a Server Action which is not present in the current deployment.

Server Reference ID did not match the expected format

This message means that the request contained a Server Action ID that was not in the format generated by the current version of Next.js.

This can happen if the client and server are running versions of Next.js that use different ID formats. It can also be caused by intentionally malformed requests, including traffic generated by automated security scanning. If neither explanation applies, a bug in Next.js may be causing a valid Server Action ID to be rejected as having an invalid format.

Possible Ways to Fix It

Ensure that your client assets and Server Actions come from the same deployment and use compatible versions of Next.js.

When self-hosting your Next.js application across multiple servers, ensure that all server instances use the same build output and encryption key. You can provide a consistent key using the process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY environment variable.

The key must be a base64-encoded value with a valid AES key length (16, 24, or 32 bytes). Set this variable at build time—the key is embedded in the build output and used automatically at runtime.

If you are deploying your Next.js application to Vercel, you can use the feature Skew Protection to ensure assets and Server Actions from the previous version are still available, even after a new version is deployed.

If unexpected-format errors occur repeatedly, confirm that the client and server use compatible versions of Next.js and check whether the requests were intentionally malformed, such as traffic generated by automated security scanning. If neither applies and you can reproduce the error with a single version of Next.js, report the issue to the Next.js project.