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

"Server Actions must be async functions." being reported incorrectly #72336

Open
chungweileong94 opened this issue Nov 5, 2024 · 0 comments
Open
Labels
bug Issue was opened via the bug report template.

Comments

@chungweileong94
Copy link
Contributor

chungweileong94 commented Nov 5, 2024

Link to the code that reproduces this issue

https://github.com/chungweileong94/nextjs-server-action-async-func-bug

To Reproduce

  1. Start the server, pnpm dev
  2. Navigate to the homepage

Current vs. Expected behavior

Expected:

  • No error

Current

  • "Server Actions must be async functions." error will shows up, but incorrectly.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: 1.22.21
  pnpm: 8.15.7
Relevant Packages:
  next: 15.0.3-canary.6 // Latest available version is detected (15.0.3-canary.6).
  eslint-config-next: N/A
  react: 19.0.0-rc-7c8e5e7a-20241101
  react-dom: 19.0.0-rc-7c8e5e7a-20241101
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

I'm an author of a small library called server-act, which the library is a simple server action builder by using the function builder pattern to construct a server action, like

const action = builder
  .input(...)
  .action(...);

However, since Next.js 15, Next.js failed to detect the async function/server action correctly. For instance:

export const action = builder
  .input(() => { ... }) // <-- Next.js keeps saying that this needs to be an async function, message: "Server Actions must be async functions."
  .action(...); // <-- this will always return an async function, aka server action

The same thing happens to one of the similar library as well, TheEdoRan/next-safe-action#288.

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.
Projects
None yet
Development

No branches or pull requests

1 participant