withastro/astro · warning
An error was encountered while creating the JSON schema for
Error message
An error was encountered while creating the JSON schema for the ${collectionKey} collection. Proceeding without it. Error: ${err} What it means
The content-layer types generator converts each collection's Zod schema into a JSON Schema file (`<collection>.schema.json`) used for editor autocompletion. If the schema contains a construct that cannot be serialized to JSON Schema (custom types, function-backed transforms/refs, problematic recursive or record shapes), generation for that one collection throws, is caught here, and logged as a warning. Content parsing and the build are unaffected — you only lose the generated schema artifact for that collection.
Source
Thrown at packages/astro/src/content/types-generator.ts:673
const def = ctx.zodSchema._zod.def;
if (def.type === 'date') {
ctx.jsonSchema.type = 'string';
ctx.jsonSchema.format = 'date-time';
}
},
// Collection schemas are used for parsing collection input, so we need to tell Zod to use the
// input shape when generating a JSON schema.
io: 'input',
});
const schemaStr = JSON.stringify(schema, null, 2);
const schemaJsonPath = new URL(
`./${collectionKey.replace(/"/g, '')}.schema.json`,
collectionSchemasDir,
);
await fsMod.promises.writeFile(schemaJsonPath, schemaStr);
} catch (err) {
// This should error gracefully and not crash the dev server
logger.warn(
'content',
`An error was encountered while creating the JSON schema for the ${collectionKey} collection. Proceeding without it. Error: ${err}`,
);
}
}
View on GitHub (pinned to e294953aa8)
Solutions
- Identify the failing collection from the `${collectionKey}` named in the message
- Simplify that collection's schema — replace z.custom/transform with JSON-representable primitives and move transforms into loader code
- If you never consume the generated .schema.json, treat the warning as cosmetic noise
- Rerun `npx astro sync` after each schema change to confirm which construct fails
Example fix
// before: not serializable to JSON Schema
const schema = z.object({
date: z.custom<Date>((v) => v instanceof Date),
});
// after: keep the schema primitive, coerce in the loader
const schema = z.object({ date: z.string() }); Defensive patterns
Strategy: validation
Validate before calling
// CI test: every collection schema must survive JSON-Schema conversion
import { zodToJsonSchema } from 'zod-to-json-schema';
import { collections } from './src/content.config.ts';
for (const [key, c] of Object.entries(collections)) {
if (c.type?.schema) {
expect(() => zodToJsonSchema(c.type.schema, key), key).not.toThrow();
}
} Prevention
- Prefer primitive zod types (string/number/enum) in collection schemas; push transforms into loaders
- Watch `astro sync` output when adding new collections — the warning names the failing collection immediately
- Don't depend on generated .schema.json artifacts for collections with custom types
When it happens
Trigger: A `defineCollection({ loader, schema })` schema using z.custom(), .transform(), z.lazy recursion, or unusual z.record key types; running `astro sync` or dev/build triggers the generator and the conversion fails for one collection key.
Common situations: Content layer collections with hand-written Zod schemas; upgrading Astro or zod versions that change JSON-Schema conversion behavior; seeing the warning during sync while everything else stays green.
Related errors
- ContentLoaderReturnsInvalidId
- Auto-generating collections for folders in "src/content/" t
- [content] Could not read the chunked data store at ${fileURL
- [RSS] You can only glob entries within 'src/pages/' when pas
- BAD_REQUEST
AI-assisted analysis of withastro/astro@e294953aa8 (2026-08-18).
Data as JSON: /api/errors/4fe5510810670877.
Report an issue: GitHub.