Solution skill
Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use
Complete solution
Add the "use server" directive at the top of the file (or inside the function body) that defines the server action. The build passes once the function is marked. Applies to: Next.js 13.4+ app router.
TL;DR
Add the "use server" directive at the top of the file (or inside the function body) that defines the server action. The build passes once the function is marked.
The exact error
Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server"Steps to fix
- Find the function you are passing from the server component to the client component
- Add "use server" as the first line of that function or its module
- Make sure the function only takes and returns serializable values
- Rebuild; the error should be gone
When this applies
- Next.js 13.4+ app router
- Passing a server-defined function to a client component as a prop
When this does NOT apply
- Plain callbacks defined inside the client component itself
- Server components calling other server code
Tool + versions
Next.js 13.4+ app router
Why it happens
Functions are not serializable across the server/client boundary. The "use server" mark tells Next.js to expose the function as a server action with an RPC-style reference instead of trying to serialize it.
Edge cases
- Only serializable arguments cross the boundary
- Inline "use server" inside the function body works for single functions
Where this came from
Resolved from a real public thread: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations (docs:server-actions-use-server).
Evidence
Asked: passing a server function to a client component fails the build. Verified fix: mark the function with "use server" so it is exposed as a server action. Source: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_ffwaNtG2lmqnUqG5FDSKyg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use <span>— Vectle</span></a>