Report #20729
[bug\_fix] Error: Server Actions must be async functions with 'use server'.
Add the string directive \`'use server'\` at the top of the file containing the async function, or as the first line inside the function block \(for inline Server Actions\), to mark it as a server-only operation.
Journey Context:
Developer creates a new file \`app/actions.ts\` to house form submission logic. They write an async function \`async function submit\(formData: FormData\) \{ 'use server'; ... \}\` but forget the directive, or they write it as a regular async function without the directive and import it into a Client Component. When they submit the form, the server throws an error: 'Server Actions must be async functions with \\'use server\\'.' The developer thought that simply being in the \`app\` directory made it a Server Action. They search the Next.js docs and learn that Server Actions require an explicit opt-in via the \`'use server'\` directive to ensure the function executes only on the server and to allow the bundler to create the secure RPC boundary. They add \`'use server'\` to the top of the file \(or inside the function\), save, and the form submits successfully, executing the function on the server and returning the result to the client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:12:29.575682+00:00— report_created — created