facebook/react · error · Error
Server actions must be functions
Error message
Server actions must be functions
What it means
loadServerAction() resolves a server action id through the parcel server manifest, preloads its chunk, then requires it. Files marked 'use server' must export only functions, so when requireModule(reference) returns anything other than a function (undefined binding, object, class), the returned promise rejects with this error.
Source
Thrown at packages/react-server-dom-parcel/src/server/ReactFlightDOMServerNode.js:803
export function decodeAction<T>(body: FormData): Promise<() => T> | null {
return decodeActionImpl(body, serverManifest);
}
export function decodeFormState<S>(
actionResult: S,
body: FormData,
): Promise<ReactFormState<S, ServerReferenceId> | null> {
return decodeFormStateImpl(actionResult, body, serverManifest);
}
export function loadServerAction<F: (...any[]) => any>(id: string): Promise<F> {
const reference = resolveServerReference<any>(serverManifest, id);
return Promise.resolve(reference)
.then(() => preloadModule(reference))
.then(() => {
const fn = requireModule(reference);
if (typeof fn !== 'function') {
throw new Error('Server actions must be functions');
}
return fn;
});
}
View on GitHub (pinned to eafeac097b)
Solutions
- Make every export in the 'use server' file an async function
- Move constants/types/classes to a plain server-side module without 'use server' and import them from the action file
- Clear the bundler cache and rebuild so the server manifest maps each action id to a live export
Example fix
// before ('use server' file)
'use server';
export const LIMITS = {max: 10}; // non-function export
export async function addItem(item) {...}
// after
// limits.js (no 'use server'): export const LIMITS = {max: 10};
'use server';
export async function addItem(item) {...} Defensive patterns
Strategy: try-catch
Try / catch
try {
const fn = await loadServerAction(id);
} catch (e) {
logger.error(`Server action ${id} failed to load: ${e.message}`);
throw e;
} Prevention
- Lint 'use server' files so every export is an async function
- Keep constants and classes out of action modules
- Rebuild both bundles after renaming exports referenced by server actions
When it happens
Trigger: A 'use server' module exporting a non-function (export const LIMITS = {...}, export default someObject, a class), or a manifest id mapping to a renamed/tree-shaken export so the required binding resolves to undefined.
Common situations: Adding constants or config objects to a 'use server' file; mixing default/class exports into action modules; stale server manifest after renaming exports while the bundler cache persists.
Related errors
- Invalid server action: ${ref}
- No server callback has been registered. Call setServerCallba
- Server actions must be functions
- Server actions must be functions
- Client Functions cannot be passed directly to Server Functio
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/f532f691b12baa30.
Report an issue: GitHub.