Report #75584
[bug\_fix] Server Action missing 'use server' directive or placed incorrectly causing 'Server Actions must be async functions' error
For inline Server Actions within a Server Component, add the \`"use server"\` directive at the top of the function body \(before any other code\) to mark it as a Server Action. For imported Server Actions from separate files, the file must have \`"use server"\` at the top of the file \(before imports\), and all exports from that file must be async Server Actions. The function must be async. If using a form action, ensure the action prop receives the Server Action function reference, not the result of calling it.
Journey Context:
Developer creates a contact form in \`app/contact/page.tsx\` \(a Server Component\). They write: \`async function submitForm\(formData: FormData\) \{ 'use server'; await saveToDb\(formData\); \}\`. But they get an error: 'Server Actions must be async functions.' They check and see they did mark it async. The issue is they put 'use server' inside the function but forgot the semicolon or had other code before it. Or they tried to define the function in a separate file without 'use server' at the top of the file. They move 'use server' to the top of the file: \`'use server'; export async function submitForm\(formData\) \{ ... \}\`. Now it works. Alternatively, if they try to pass the action to a form: \`\` \(calling it\) instead of \`\`, they get errors about serializing the return value. They realize Server Actions are invoked by the framework, not called directly in JSX.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:27:38.843289+00:00— report_created — created