withastro/astro · warning
Your loader's schema is defined using a function. This is no
Error message
Your loader's schema is defined using a function. This is no longer supported and the schema will be ignored. Please update your loader to use the `createSchema()` utility instead, or report this to the loader author. In a future major version, this will cause the loader to break entirely.
What it means
The zod validation of your content config detected a loader object whose `schema` is a plain function. The Content Layer API expects schemas as a zod schema object or created via createSchema(); the function form is transformed to undefined and ignored with this deprecation warning, and a future major version will break such loaders entirely.
Source
Thrown at packages/astro/src/content/utils.ts:88
z.object({
type: z.literal(CONTENT_LAYER_TYPE),
schema: z.any().optional(),
loader: z.union([
z.function(),
z.object({
name: z.string(),
load: z.function({
input: [z.custom<LoaderContext>()],
output: z.custom<{
schema?: any;
types?: string;
} | void>(),
}),
schema: z
.any()
.transform((v) => {
if (typeof v === 'function') {
logger.warn(
'content',
`Your loader's schema is defined using a function. This is no longer supported and the schema will be ignored. Please update your loader to use the \`createSchema()\` utility instead, or report this to the loader author. In a future major version, this will cause the loader to break entirely.`,
);
return undefined;
}
return v;
})
.superRefine((v, ctx) => {
if (v !== undefined && !('_zod' in v)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Invalid Zod schema',
});
return z.NEVER;
}
})
.optional(),
createSchema: zView on GitHub (pinned to e294953aa8)
Solutions
- Import createSchema from 'astro:content' and wrap the schema: schema: createSchema(({ image }) => z.object({...}))
- If the loader is third-party, upgrade it or report the warning to its author
- Alternatively return a plain zod schema object rather than a function
Example fix
// before: custom-loader.ts
export function myLoader(): Loader {
return {
name: 'my-loader',
load: async ({ store, logger }) => { /* ... */ },
schema: () => z.object({ title: z.string() }),
};
}
// after
import { createSchema } from 'astro:content';
export function myLoader(): Loader {
return {
name: 'my-loader',
load: async ({ store, logger }) => { /* ... */ },
schema: createSchema(() => z.object({ title: z.string() })),
};
} Defensive patterns
Strategy: type-guard
Validate before calling
// Warn at loader-construction time if a legacy function schema slips in
function assertModernSchema(loader: { schema?: unknown }) {
if (typeof loader.schema === 'function') {
throw new Error('Loader schema must use createSchema(), not a function');
}
} Type guard
interface ModernLoader { schema?: object; createSchema?: () => Promise<{ schema: object }> }
function usesLegacyFunctionSchema(loader: { schema?: unknown }): loader is { schema: () => unknown } {
return typeof loader.schema === 'function';
} Prevention
- Always author loader schemas with createSchema() from 'astro:content'
- When adopting a third-party loader, check its changelog for createSchema support
- Watch deprecation warnings after major upgrades — they become hard errors in the next major
When it happens
Trigger: Writing a custom loader with schema: () => z.object({...}) instead of schema: createSchema((ctx) => z.object({...})); using a third-party loader written against the pre-createSchema API.
Common situations: Copy-pasting older examples or blog posts; community loaders (CMS adapters, etc.) not yet updated; upgrading a project across the Astro 4 to 5 boundary where the loader API changed.
Understand the failure class
Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.
Related errors
- Auto-generating collections for folders in "src/content/" t
- [content] Could not read the chunked data store at ${fileURL
- ContentLoaderReturnsInvalidId
- ContentLoaderInvalidDataError
- ExpectedImageOptions
AI-assisted analysis of withastro/astro@e294953aa8 (2026-09-09).
Data as JSON: /api/errors/cb7f7978384fb0b5.
Report an issue: GitHub.