Report #95818
[bug\_fix] Server Action cannot be passed to Client Component without 'use server' directive
Add the 'use server' directive at the top of the file containing the Server Action \(before imports\), or mark the specific function with 'use server' if defined inline, to allow it to be safely imported and called from Client Components.
Journey Context:
Developer creates a file \`actions.ts\` containing an async function that uses SQL to insert data into a database. They import this function into a Client Component \('use client'\) form component and attach it to the form's action attribute or call it directly. Next.js throws: 'Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server"'. Developer tries adding 'use server' inside the function body, which works for inline actions but not for imported modules. The issue is that for a function to be imported into a Client Component as a Server Action, the file must be marked with the 'use server' directive at the very top, indicating all exports are server-side functions that can be invoked from the client via a special protocol. Without this directive, Next.js treats it as a regular function that cannot be serialized and passed to the client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:24:41.704238+00:00— report_created — created