{"record":{"id":"35d38ff99b58edf0","repo":"withastro/astro","slug":"unsupportedconfigtransformerror","errorCode":"UnsupportedConfigTransformError","errorMessage":"`transform()` functions in your content config must return valid JSON, or data types compatible with the devalue library (including Dates, Maps, and Sets).\nFull error: ${parseError}","messagePattern":"`transform\\(\\)` functions in your content config must return valid JSON, or data types compatible with the devalue library \\(including Dates, Maps, and Sets\\)\\.\nFull error: (.+?)","errorType":"error_code","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/vite-plugin-content-imports.ts","lineNumber":434,"sourceCode":"/** Stringify entry `data` at build time to be used as a Vite module */\nfunction stringifyEntryData(data: Record<string, any>, isSSR: boolean): string {\n\ttry {\n\t\treturn devalue.uneval(data, (value) => {\n\t\t\t// Add support for URL objects\n\t\t\tif (value instanceof URL) {\n\t\t\t\treturn `new URL(${JSON.stringify(value.href)})`;\n\t\t\t}\n\n\t\t\t// For Astro assets, add a proxy to track references\n\t\t\tif (typeof value === 'object' && 'ASTRO_ASSET' in value) {\n\t\t\t\tconst { ASTRO_ASSET, ...asset } = value;\n\t\t\t\tasset.fsPath = ASTRO_ASSET;\n\t\t\t\treturn getProxyCode(asset, isSSR);\n\t\t\t}\n\t\t});\n\t} catch (e) {\n\t\tif (e instanceof Error) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.UnsupportedConfigTransformError,\n\t\t\t\tmessage: AstroErrorData.UnsupportedConfigTransformError.message(e.message),\n\t\t\t\tstack: e.stack,\n\t\t\t});\n\t\t} else {\n\t\t\tthrow new AstroError({\n\t\t\t\tname: 'PluginContentImportsError',\n\t\t\t\tmessage: 'Unexpected error processing content collection data.',\n\t\t\t});\n\t\t}\n\t}\n}\n","sourceCodeStart":416,"sourceCodeEnd":447,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/content/vite-plugin-content-imports.ts#L416-L447","documentation":"Thrown when a `transform()` function in a content collection schema returns a value that cannot be serialized by the devalue library. After the transform runs, the plugin attempts to serialize the result for the virtual module; if devalue encounters an unsupported type (e.g. a class instance, a function, a Symbol, a circular reference), it throws, and the error is wrapped as `UnsupportedConfigTransformError`.","triggerScenarios":"A collection schema uses `.transform()` (or Zod's `.transform()`) and the transform returns a non-serializable value. The `stringify`/devalue serialization step in the content imports plugin throws, the catch block wraps it with the full devalue parse error message.","commonSituations":"A transform returns a class instance (e.g. `new Date()` is fine, but `new MyClass()` is not). A transform returns a function or callback. A circular object reference in transformed data. Returning a Map with non-serializable keys or a Symbol-keyed object.","solutions":["Return only JSON-compatible types or devalue-supported types (Date, Map, Set, URL, RegExp, BigInt, TypedArray).","Convert class instances to plain objects before returning from transform.","Break circular references or use a structure that avoids them.","Read the devalue parse error in the message — it names the unsupported type."],"exampleFix":"// before\nschema: z.object({\n  date: z.string().transform((s) => {\n    const d = new MyCustomDate(s); // class instance — not serializable\n    return d;\n  }),\n}),\n\n// after\nschema: z.object({\n  date: z.coerce.date(), // native Date — devalue supports it\n}),","handlingStrategy":"validation","validationCode":"import { stringify } from 'devalue';\nfunction isSerializable(value: unknown): boolean {\n  try { stringify(value); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await getCollection('blog');\n} catch (e) {\n  if (e instanceof Error && /UnsupportedConfigTransformError/.test(e.name)) {\n    console.error('Transform returned non-serializable data:', e.message);\n  }\n  throw e;\n}","preventionTips":["Only return JSON-compatible types or devalue-supported types from transform().","Test transforms with devalue.stringify in unit tests.","Convert class instances to plain objects before returning."],"tags":["content-collections","transform","serialization","devalue","zod"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}