2 months ago
Hi, I am getting the exception below every day. Not sure of the reason. Could you please help?
[Error: Failed to find Server Action "x". This request might be from an older or newer deployment.
Read more: https://nextjs.org/docs/messages/failed-to-find-server-action]
Pinned Solution
2 months ago
did you actually redeploy after adding the encryption key? the key needs to be present during the BUILD, not just added while service is running
also important to check your railway deployment logs. if this happens every day at 10:30 am, something is triggering a restart or redeploy , railway doesn't have automatic daily restarts by default so check if you have any cron jobs set up that restart the service or github auto-deploys are triggering (if you push code daily) or maybe some memory issues causing crashes
so look at your deployment logs around 10:30 am to see what's actually happening. the encryption key fixes the error but only if your service isn't actually restarting daily
11 Replies
2 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 2 months ago
2 months ago
you need to set a persistent encryption key for server actions. run openssl rand -base64 32 to generate one, then add it as NEXT_SERVER_ACTIONS_ENCRYPTION_KEY in your railway env vars.
important: make sure it's available at build time not just runtime. redeploy after adding it and the error should stop happening daily
2 months ago
where should i add, backend variables or frontend ?
2 months ago
backend variables
server actions run on the server side, so the encryption key needs to be in your backend/service environment variables, not frontend
2 months ago
The cause:
This happens because of caching, if the app is rebuilt it changes server actions ids, so if a browser hasn't refreshed the page after you made a new build it still uses old cached data to communicate with your next.js server, thus resulting in an unfound action id.
The fix:
Locally, you could delete .next folder before making a new build and refresh your browser. This usually gets rid of the error.
In production however, refreshing the page also does the trick, but if the problem persists you could try Skew protection to sync the client with the server, to prevent old client versions from communicating with your updated server code.
This is usually harmless and it goes away once all clients are refreshed.
darseen
The cause:This happens because of caching, if the app is rebuilt it changes server actions ids, so if a browser hasn't refreshed the page after you made a new build it still uses old cached data to communicate with your next.js server, thus resulting in an unfound action id.The fix:Locally, you could delete .next folder before making a new build and refresh your browser. This usually gets rid of the error.In production however, refreshing the page also does the trick, but if the problem persists you could try Skew protection to sync the client with the server, to prevent old client versions from communicating with your updated server code.This is usually harmless and it goes away once all clients are refreshed.
2 months ago
sorry, but i don't agree with you because this happens to him every single day, that means something is triggering a daily restart which isn't normal, and i think the encryption key is the documented solution from next.js
let us know the result @earnwithsurekha
domehane
sorry, but i don't agree with you because this happens to him every single day, that means something is triggering a daily restart which isn't normal, and i think the encryption key is the documented solution from next.jslet us know the result @earnwithsurekha
2 months ago
The encryption key is definitley a valid solution, and he should try it of course. But it's more for a next application that is hosted on multiple servers, which in this case it means that all server instances use the same key as stated in the docs.
With that said, I had this issue before and it was related to caching, so the solution was to refresh clients browsers to be up to date with the new build.
But as I said, OP should try both solutions as they are both valid.
2 months ago
I am still seeing the issue even after adding NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
Attachments
earnwithsurekha
I am still seeing the issue even after adding NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
2 months ago
did you actually redeploy after adding the encryption key? the key needs to be present during the BUILD, not just added while service is running
also important to check your railway deployment logs. if this happens every day at 10:30 am, something is triggering a restart or redeploy , railway doesn't have automatic daily restarts by default so check if you have any cron jobs set up that restart the service or github auto-deploys are triggering (if you push code daily) or maybe some memory issues causing crashes
so look at your deployment logs around 10:30 am to see what's actually happening. the encryption key fixes the error but only if your service isn't actually restarting daily
2 months ago
Since the env var solution didn't work, here is another possible way to fix it:
First let me explain to you why this error occurs to help you debug it.
This error typically happens when there is a "version skew"
a user loads your website (version A).
you deploy a new update (version B) while they are still browsing.
the user clicks a button that triggers a server action.
the browser sends the id from version A
the server (now running version B) receives the id, doesn't recognize it (because ids changed in the rebuild), and throws this error.
So, if you have another service or a cron job that interact with your next.js app, make sure to restart them after making a new build. Or if you are sending action id in the request header, it will be invalid when you rebuild your app.
Try this fix and see if it works:// next.config.js
module.exports = {
generateBuildId: async () => {
// this could be anything, using the latest git hash
// this helps next.js identify which build the client is talking to.
return process.env.GIT_HASH;
},
}
You can use openssl rand -base64 32 to generate a build id if you don't have a git hash.
earnwithsurekha
Thanks for your help. I didn't see any such exceptions today.
2 months ago
your welcome 
Status changed to Solved ray-chen • 2 months ago
