-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to find server action/Cannot read properties of undefined (reading 'workers') #72638
Comments
Downgrading to |
We have a similar problem with server action. We have a function to connect to the database through mysql2 library, which is called in server action. Locally everything works fine, but in the production build when using server action the page crashes. The problem is observed in version ‘15.0.3’ and higher (15.0.4-canary.18)). And it is reproduced only when using server action. At the moment we have solved it by rolling back to ‘15.0.2’. A similar problem was described here - sidorares/node-mysql2#3213 (The error message is identical to ours.). |
@lemurki, I feel like that is something different. The error |
@kevva I think the root of the problem in our project and yours is in optimising server action. That's why I wrote that the problem is similar :) For curiosity sake, try to upgrade to version 15.0.2 and see if the server action problem remains in your project. |
By optimizing I mean that Next.js is running an optimization that removes any server actions it thinks isn't in use from the actions manifest. This is so that they aren't exposed unnecessarily on pages that doesn't need them.
It does remain. |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/sweet-dan-qdctsl
To Reproduce
yarn && yarn build
cd apps/foo && yarn start
Current vs. Expected behavior
Current behaviour:
Sometimes when server actions are called they throw a
Failed to find server action/Cannot read properties of undefined (reading 'workers')
error. This is most likely due to Next.js not recognizing which server actions should be included on a page.Expected behaviour:
Server actions run without errors. Not sure how to better define it.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000 Available memory (MB): 32768 Available CPU cores: 10 Binaries: Node: 23.2.0 npm: 10.2.4 Yarn: 4.5.1 pnpm: N/A Relevant Packages: next: 15.0.4-canary.5 eslint-config-next: N/A react: 19.0.0-rc-5c56b873-20241107 react-dom: 19.0.0-rc-5c56b873-20241107 typescript: 5.6.3 Next.js Config: output: standalone
Which area(s) are affected? (Select all that apply)
Output (export/standalone), Partial Prerendering (PPR), Runtime
Which stage(s) are affected? (Select all that apply)
next start (local), Other (Deployed)
Additional context
The reproduction example will work correctly, and it (always) works locally when running our application as well. On our deployment it's another thing though and I've been trying to figure out what's causing it for a few weeks now without any luck. I'm not sure how often it happens, because the app mostly works when I use it, but the logs and Sentry is telling me another story.
The code in the reproduction example works and looks mostly the same as in our application though so it should be a good representation of it. We have a internal package in our monorepo which exports server components and actions. We initiate the actions with some other server actions coming from the app that holds logic not suitable for the internal package. Then we wrap them in additional actions from the app that might do redirection or whatever when everything is done. Finally we pass them down to the server components from the internal package where they're sometimes called from a client component and sometimes directly from a server component.
We deploy this to Kubernetes running multiple containers and we set
generateBuildId
to the SHA for the current commit anddeploymentId
to the deployment ID in our pipeline so it should be consistent between builds and deploys. We're also setting theNEXT_SERVER_ACTIONS_ENCRYPTION_KEY
to avoid any inconsistencies between containers. I've also included a minimal example of ourDockerfile
(we're using a customnode
image though so not sure it runs).Is there some way to debug this? Would it be possible to add a flag to turn off optimization for unused server actions?
The text was updated successfully, but these errors were encountered: