sveltejs/kit · error · Error
Data returned from action inside ${route_id} is not serializ
Error message
Data returned from action inside ${route_id} is not serializable: ${error.message} (data.${error.path}) What it means
Devalue failed to serialize a property of the object returned from a form action (or one nested under `fail` data). Because the serialization error carries a `path`, SvelteKit augments the message with the exact offending property (e.g. `data.items.0.date`) so you can fix the returned shape.
Source
Thrown at packages/kit/src/runtime/server/page/actions.js:320
try {
return fn(data);
} catch (e) {
// If we're here, the data could not be serialized with devalue
const error = /** @type {any} */ (e);
// if someone tries to use `json()` in their action
if (data instanceof Response) {
throw new Error(
`Data returned from action inside ${route_id} is not serializable. Form actions need to return plain objects or fail(). E.g. return { success: true } or return fail(400, { message: "invalid" });`,
{ cause: e }
);
}
// if devalue could not serialize a property on the object, etc.
if ('path' in error) {
let message = `Data returned from action inside ${route_id} is not serializable: ${error.message}`;
if (error.path !== '') message += ` (data.${error.path})`;
throw new Error(message, { cause: e });
}
throw error;
}
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Map the offending property (see `data.<path>` in the message) to a plain value: `String(bigintValue)`, `.toISOString()` for dates, spread ORM rows into POJOs
- Strip functions, class instances, and `undefined` from the returned object
- Verify the return type of every branch of your action (including `fail` data)
Example fix
// before
export const actions = {
default: async () => {
const user = await db.user.findFirst();
return { user }; // contains BigInt id
}
};
// after
export const actions = {
default: async () => {
const user = await db.user.findFirst();
return { user: { ...user, id: String(user.id), createdAt: user.createdAt.toISOString() } };
}
}; Defensive patterns
Strategy: validation
Validate before calling
// sanity check before returning
const data = { items };
JSON.stringify(data); // throws/spot-checks most non-serializable values Prevention
- Convert BigInt/Date/Map/Set/class instances to JSON-friendly primitives before returning
- Spread ORM results into plain objects; select only needed columns
- Read the `data.<path>` in the message to locate the offending field quickly
When it happens
Trigger: Returning values devalue cannot encode from an action: `undefined` in arrays, class instances, functions, `BigInt`, `Symbol`, cyclic references, `Date` inside certain positions, or a promise stored on the returned object.
Common situations: Returning ORM entities/Mongoose docs or Prisma objects with methods; returning rows containing `BigInt` IDs; accidental inclusion of functions (e.g. attaching helpers to the result); non-JSON dates or Maps/Sets in older devalue configurations.
Related errors
- Data returned from action inside ${route_id} is not serializ
- called uneval before init_transport
- called stringify before init_transport
- called parse before init_transport
- Cannot `return redirect(...)` — use `redirect(...)` instead
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/bb118ebfa3befcbd.
Report an issue: GitHub.