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}.

What it means

`defineLiveCollection` is only valid when called from `src/live.config.ts`. The function inspects the importer filename via `getImporterFilename()`; if the filename does not contain `live.config`, it throws `LiveContentConfigError`. Live collections are a separate config stream from build-time content collections and must live in their own file.

Source

Thrown at packages/astro/src/content/config.ts:122

	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 d081033d5f)

Solutions

  1. Create `src/live.config.ts` and move the `defineLiveCollection(...)` call there.
  2. Leave build-time `defineCollection` calls in `src/content/config.ts`.
  3. Make sure the filename literally contains the substring `live.config` (e.g. `src/live.config.ts`).

Example fix

// before — src/content/config.ts
import { defineLiveCollection } from 'astro:content';
export const collections = { live: defineLiveCollection({ loader }) };
// after — src/live.config.ts
import { defineLiveCollection } from 'astro:content';
export const collections = { live: defineLiveCollection({ loader }) };
Defensive patterns

Strategy: validation

Validate before calling

const file = getImporterFilename();
if (file && !file.includes('live.config')) {
  throw new Error('Move defineLiveCollection to src/live.config.ts');
}

Prevention

When it happens

Trigger: Calling `defineLiveCollection(...)` inside `src/content/config.ts` (or any file whose path does not include `live.config`).

Common situations: Migrating to live collections but keeping the definition in the existing `content/config.ts`; copy-pasting a live collection example into the wrong config file; renaming `live.config.ts` to something else.

Related errors


AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12). Data as JSON: /api/errors/c83c60026b466a72. Report an issue: GitHub.