Next.js Server Action Not Callable from Client Component
Your Next.js server action defined with 'use server' directive isn't callable from client components, or throws 'function not defined' errors. Forms and onClick handlers can't invoke server actions.
Server actions fail when not properly imported, 'use server' is misplaced, or there's a server-client boundary violation in how the action is used.
Error Messages You Might See
Common Causes
- 'use server' directive in client component instead of server file or top of function
- Server action file not properly exported or imported in client component
- Passing non-serializable objects to server action (functions, class instances)
- Server action defined in client component file with 'use client'
- Async/await not properly handled when calling server action
How to Fix It
Create server action file: Make separate file with 'use server' at top, export the async function:'use server'
export async function submitForm(formData) { ... }
Import in client: In client component, import and call normally:import { submitForm } from '@/actions'
onClick={() => submitForm(data)}
Handle async: Wrap in useTransition hook for loading state:const [pending, startTransition] = useTransition()
startTransition(() => submitForm(data))
Pass FormData: For forms, pass FormData object directly, not individual fields.
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
Where do I define server actions?
In a separate file with 'use server' at the top, or at function level inside a server component.
Can server actions access databases?
Yes, that's their main purpose. Server actions run only on server, so database queries are safe and secret keys protected.
How do I show loading state during server action?
Use useTransition hook: const [pending] = useTransition(); pending shows true while action runs.