Report #46400
[bug\_fix] 'use server' directive must be at the top of the function or file or Error: Server Actions must be async functions
Place 'use server' at the very top of the file \(before imports\) if the file exports multiple server actions. For inline server actions inside Client Components, place 'use server' inside the function body before the logic. Ensure the function is async.
Journey Context:
Developer creates a form in a Client Component and wants to use a Server Action. They create \`actions.ts\` and export an async function but forget 'use server'. When imported, it errors saying it's not a Server Action. They add 'use server' to the top of actions.ts. It works. Later, they try to define a server action inline in their Client Component and put 'use server' at the top of the file by mistake, getting an error that it can't be used on the client. They realize 'use server' inside a function body makes that specific function a server action when defined in a client file. They understand the distinction between file-level \(for shared actions\) and function-level \(for inline actions\) directives.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:21:21.499541+00:00— report_created — created