{"record":{"id":"65d3f051c0b543aa","repo":"sveltejs/kit","slug":"data-returned-from-action-inside-route-id-is-no","errorCode":null,"errorMessage":"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\" });","messagePattern":"Data returned from action inside (.+?) is not serializable\\. Form actions need to return plain objects or fail\\(\\)\\. E\\.g\\. return (.+?) or return fail\\(400, (.+?)\\);","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/server/page/actions.js","lineNumber":310,"sourceCode":"export function uneval_action_response(data, route_id) {\n\treturn try_serialize(data, uneval, route_id);\n}\n\n/**\n * @param {any} data\n * @param {(data: any) => string} fn\n * @param {string} route_id\n */\nfunction try_serialize(data, fn, route_id) {\n\ttry {\n\t\treturn fn(data);\n\t} catch (e) {\n\t\t// If we're here, the data could not be serialized with devalue\n\t\tconst error = /** @type {any} */ (e);\n\n\t\t// if someone tries to use `json()` in their action\n\t\tif (data instanceof Response) {\n\t\t\tthrow new Error(\n\t\t\t\t`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\" });`,\n\t\t\t\t{ cause: e }\n\t\t\t);\n\t\t}\n\n\t\t// if devalue could not serialize a property on the object, etc.\n\t\tif ('path' in error) {\n\t\t\tlet message = `Data returned from action inside ${route_id} is not serializable: ${error.message}`;\n\t\t\tif (error.path !== '') message += ` (data.${error.path})`;\n\t\t\tthrow new Error(message, { cause: e });\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n","sourceCodeStart":292,"sourceCodeEnd":326,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/page/actions.js#L292-L326","documentation":"Action return values are serialized with devalue and shipped to the client. `try_serialize` caught a devalue failure and detected the returned data is actually a `Response` — e.g. someone used `json(...)` in a form action — which cannot be used as an action result. Form actions must return plain objects or `fail()`.","triggerScenarios":"Returning `json(data)` from a `+page.server.js` action; returning a raw `Response` object from an action; any action data that devalue cannot serialize when it happens to be a Response instance.","commonSituations":"Copying `+server.js` handler code (where returning `json()` is valid) into a form action; mixing up load/handle code with action code; refactoring an endpoint into an action without changing the return type.","solutions":["Return a plain serializable object instead of `json()`: `return { success: true }`","Use `return fail(status, data)` for error responses","If you truly need a custom Response, use a `+server.js` endpoint, not a form action"],"exampleFix":"// before\nimport { json } from '@sveltejs/kit';\nexport const actions = { default: async () => json({ ok: true }) };\n// after\nexport const actions = { default: async () => ({ ok: true }) };","handlingStrategy":"type-guard","validationCode":"// before returning from an action\nif (result instanceof Response) {\n  throw new TypeError('Actions must return plain objects or fail(), not Responses');\n}","typeGuard":"/** @returns {result is Record<string, any>} */\nfunction isPlainActionResult(result) {\n  return !(result instanceof Response);\n}","tryCatchPattern":null,"preventionTips":["Never use json()/Response returns in +page.server.js actions","Return POJOs only; move custom-response logic to +server.js endpoints","Type action returns with the ActionData type from generated types"],"tags":["sveltekit","form-actions","serialization","devalue"],"backgroundTag":"action-return-not-serializable","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}