Skip to content
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

Open
kevva opened this issue Nov 12, 2024 · 5 comments
Labels
bug Issue was opened via the bug report template. Output (export/standalone) Related to the the output option in `next.config.js`. Partial Prerendering (PPR) Related to Partial Prerendering. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@kevva
Copy link
Contributor

kevva commented Nov 12, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/sweet-dan-qdctsl

To Reproduce

  1. Run yarn && yarn build
  2. Run cd apps/foo && yarn start
  3. Submit the form

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.

image

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 and deploymentId to the deployment ID in our pipeline so it should be consistent between builds and deploys. We're also setting the NEXT_SERVER_ACTIONS_ENCRYPTION_KEY to avoid any inconsistencies between containers. I've also included a minimal example of our Dockerfile (we're using a custom node 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?

@kevva kevva added the bug Issue was opened via the bug report template. label Nov 12, 2024
@github-actions github-actions bot added Output (export/standalone) Related to the the output option in `next.config.js`. Partial Prerendering (PPR) Related to Partial Prerendering. Runtime Related to Node.js or Edge Runtime with Next.js. labels Nov 12, 2024
@kevva
Copy link
Contributor Author

kevva commented Nov 17, 2024

Downgrading to 15.0.0-canary.125 (the version just before the optimization of server actions was introduced) does completely fix the issue so I don't think there's anything wrong with how our environment is setup unless I'm missing something that was introduced after that.

@lemurki
Copy link

lemurki commented Nov 18, 2024

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.).

@kevva
Copy link
Contributor Author

kevva commented Nov 19, 2024

@lemurki, I feel like that is something different. The error Cannot read properties of undefined (reading 'workers') comes directly from Next.js itself when it tries to get and run a non-existing server action from the actions manifest. Yours does sound like it's coming from the module you're trying to use but I can't comment on why.

@lemurki
Copy link

lemurki commented Nov 19, 2024

@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.

@kevva
Copy link
Contributor Author

kevva commented Nov 19, 2024

I think the root of the problem in our project and yours is in optimising server action.

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.

For curiosity sake, try to upgrade to version 15.0.2 and see if the server action problem remains in your project.

It does remain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Output (export/standalone) Related to the the output option in `next.config.js`. Partial Prerendering (PPR) Related to Partial Prerendering. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants