{"record":{"id":"d4920c0827421acd","repo":"vercel/next.js","slug":"error-serializing-path-returned-from-metho-d4920c","errorCode":null,"errorMessage":"Error serializing `${path}` returned from `${method}` in \"${page}\".\nReason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.","messagePattern":"Error serializing `(.+?)` returned from `(.+?)` in \"(.+?)\"\\.\nReason: `undefined` cannot be serialized as JSON\\. Please use `null` or omit this value\\.","errorType":"exception","errorClass":"SerializableError","httpStatus":null,"severity":"error","filePath":"packages/next/src/lib/is-serializable-props.ts","lineNumber":71,"sourceCode":"  ): true {\n    const type = typeof value\n    if (\n      // `null` can be serialized, but not `undefined`.\n      value === null ||\n      // n.b. `bigint`, `function`, `symbol`, and `undefined` cannot be\n      // serialized.\n      //\n      // `object` is special-cased below, as it may represent `null`, an Array,\n      // a plain object, a class, et al.\n      type === 'boolean' ||\n      type === 'number' ||\n      type === 'string'\n    ) {\n      return true\n    }\n\n    if (type === 'undefined') {\n      throw new SerializableError(\n        page,\n        method,\n        path,\n        '`undefined` cannot be serialized as JSON. Please use `null` or omit this value.'\n      )\n    }\n\n    if (isPlainObject(value)) {\n      visit(refs, value, path)\n\n      if (\n        Object.entries(value).every(([key, nestedValue]) => {\n          const nextPath = regexpPlainIdentifier.test(key)\n            ? `${path}.${key}`\n            : `${path}[${JSON.stringify(key)}]`\n\n          const newRefs = new Map(refs)\n          return (","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/lib/is-serializable-props.ts#L53-L89","documentation":"Thrown by isSerializableProps() when a property value anywhere in the props tree is strictly `undefined`. JSON.stringify silently drops undefined values, which would cause the client to receive props missing fields unexpectedly, so Next.js fails fast and asks for null or omission instead.","triggerScenarios":"During deep traversal, typeof value === 'undefined' for any leaf or nested property of the returned props. Common when a DB field is absent (returns undefined), an optional API response omits a key, or a conditional expression yields undefined.","commonSituations":"Optional database columns that are null in some rows but undefined in code paths; spreading an object whose keys are conditionally undefined; deserialization that leaves undefined gaps; or default parameters that fall through to undefined.","solutions":["Coalesce undefined values to null: `value ?? null`.","Strip undefined keys before returning: build the props object with only defined fields, or run a sanitiser that deletes undefined properties.","Provide explicit defaults so fields are always a serializable type (string, number, boolean, null, array, plain object).","If using TypeScript, type the props bag so undefined is not allowed (no optional properties whose absence matters)."],"exampleFix":"// before\nexport async function getStaticProps() {\n  const u = await getUser(id)\n  return { props: { user: { name: u.name, bio: u.bio } } } // bio may be undefined\n}\n// after\nexport async function getStaticProps() {\n  const u = await getUser(id)\n  return {\n    props: { user: { name: u.name, bio: u.bio ?? null } },\n  }\n}","handlingStrategy":"validation","validationCode":"function stripUndefined(obj: unknown): unknown {\n  if (Array.isArray(obj)) return obj.map(stripUndefined)\n  if (obj && typeof obj === 'object') {\n    return Object.fromEntries(\n      Object.entries(obj)\n        .filter(([, v]) => v !== undefined)\n        .map(([k, v]) => [k, stripUndefined(v)])\n    )\n  }\n  return obj\n}\n// in getStaticProps: return { props: stripUndefined(props) }","typeGuard":"function hasUndefinedLeaves(v: unknown): boolean {\n  if (v === undefined) return true\n  if (v && typeof v === 'object') {\n    return Object.values(v).some(hasUndefinedLeaves)\n  }\n  return false\n}","tryCatchPattern":null,"preventionTips":["Coalesce optional DB fields with `?? null`.","Strip undefined keys before returning props.","Type props bags to disallow undefined (avoid optional properties).","Add a serialize pre-check in dev builds."],"tags":["serialization","getstaticprops","getserversideprops","build","data-fetching"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}