withastro/astro · error · AstroError
LiveContentConfigError
LiveContentConfigError
Error message
Live collections must be defined in a `src/live.config.ts` file. Check your collection definitions in ${importerFilename ?? 'your content config file'}. What it means
`defineLiveCollection` inspects the stack trace to find its importing file and refuses to run outside a `live.config` file. Live collections (request-time data with live loaders) are only valid when defined in `src/live.config.ts`; the config file location is part of the contract, so defining them anywhere else — including `src/content.config.ts` — is rejected with LiveContentConfigError.
Solutions
- Move every `defineLiveCollection` call into `src/live.config.ts`
- Keep shared schemas/loaders in separate modules and import them from live.config.ts — only the define* calls must live in the config file itself
- If the collection is actually build-time, use `defineCollection` in src/content.config.ts instead
Example fix
// before — src/content.config.ts
import { defineLiveCollection } from 'astro:content';
export const collections = { posts: defineLiveCollection({ loader }) };
// after — src/live.config.ts
export const collections = { posts: defineLiveCollection({ loader }) }; Defensive patterns
Strategy: validation
Validate before calling
// guard shared config modules: only allow defineLiveCollection from live.config.*
const file = import.meta.url;
if (!/live\.config\.[cm]?[jt]s$/.test(file)) {
throw new Error('defineLiveCollection may only be called from src/live.config.ts');
}
export const collections = { posts: defineLiveCollection({ loader }) }; Prevention
- Keep exactly two config files: src/content.config.ts (build-time) and src/live.config.ts (live) — never define live collections elsewhere
- Put shared schemas/loaders in plain modules and import them; only the define* calls must sit in the config file
- During migration, move collections one at a time and run `astro build`/dev after each move
When it happens
Trigger: Calling `defineLiveCollection({...})` in `src/content.config.ts`, a shared `collections.ts` helper module, or any file whose name does not contain 'live.config'; re-exporting or wrapping defineLiveCollection from a utility module (the stack-walk still finds the ultimate importer).
Common situations: Migrating to live collections and leaving definitions in the old content config; teams putting all collection config in one shared file; helper modules for schemas that also define collections.
Related errors
- Live content collections must be defined in…
- A content collection is defined with legacy features (e.g…
- AdapterSupportOutputMismatch
- An error was encountered while creating the JSON schema for…
- Auto-generating collections for folders in "src/content/"…
AI-assisted analysis of withastro/astro@157c500c38 (2026-08-18).
Data as JSON: /api/errors/c83c60026b466a72.
Report an issue: GitHub.
Appendix: source
Thrown at packages/astro/src/content/config.ts:123
S extends BaseSchema | undefined = undefined,
> = {
type?: 'live';
schema?: S;
loader: L;
};
export type CollectionConfig<
S extends BaseSchema,
TLoader extends LoaderConstraint<{ id: string }> = LoaderConstraint<{ id: string }>,
> = ContentCollectionConfig<S> | DataCollectionConfig<S> | ContentLayerConfig<S, TLoader>;
export function defineLiveCollection<
L extends LiveLoader,
S extends BaseSchema | undefined = undefined,
>(config: LiveCollectionConfig<L, S>): LiveCollectionConfig<L, S> {
const importerFilename = getImporterFilename();
if (importerFilename && !importerFilename.includes('live.config')) {
throw new AstroError({
...AstroErrorData.LiveContentConfigError,
message: AstroErrorData.LiveContentConfigError.message(
'Live collections must be defined in a `src/live.config.ts` file.',
importerFilename ?? 'your content config file',
),
});
}
// Default to live content type if not specified
config.type ??= LIVE_CONTENT_TYPE;
if (config.type !== LIVE_CONTENT_TYPE) {
throw new AstroError({
...AstroErrorData.LiveContentConfigError,
message: AstroErrorData.LiveContentConfigError.message(
'Collections in a live config file must have a type of `live`.',
importerFilename,
),
});View on GitHub (pinned to 157c500c38)