withastro/astro · error · AstroError

UnknownContentCollectionError

UnknownContentCollectionError

Error message

Collection "${collection}" is a live collection. Use getLiveCollection() instead of getCollection().

What it means

Thrown when getCollection() is called with the name of a collection that was registered as a live collection. Live collections have a different data path (fetched on demand) and must be accessed via getLiveCollection(); the standard getCollection() refuses to silently return stale or empty results.

Source

Thrown at packages/astro/src/content/runtime.ts:105

				collection,
				`Unexpected error parsing entry ${entry.id} in collection ${collection}`,
				error as Error,
			),
		};
	}
}

export function createGetCollection({
	liveCollections,
}: {
	liveCollections: LiveCollectionConfigMap;
}) {
	return async function getCollection(
		collection: string,
		filter?: ((entry: any) => unknown) | Record<string, unknown>,
	) {
		if (collection in liveCollections) {
			throw new AstroError({
				...AstroErrorData.UnknownContentCollectionError,
				message: `Collection "${collection}" is a live collection. Use getLiveCollection() instead of getCollection().`,
			});
		}

		const hasFilter = typeof filter === 'function';
		const store = await globalDataStore.get();
		if (await store.hasCollection(collection)) {
			// @ts-expect-error	virtual module
			const { default: imageAssetMap } = await import('astro:asset-imports');

			const result = [];
			for (const rawEntry of await store.values<DataEntry>(collection)) {
				const data = resolveEntryData(rawEntry, imageAssetMap);

				let entry = {
					...rawEntry,
					data,

View on GitHub (pinned to d081033d5f)

Solutions

  1. Use getLiveCollection('name') instead of getCollection('name').
  2. Double-check src/live.config.ts and src/content/config.ts to confirm which collections are live.
  3. If you intended a static collection, move its definition out of live.config.ts into the standard content config.

Example fix

// before
const posts = await getCollection('news');
// after
const posts = await getLiveCollection('news');
Defensive patterns

Strategy: type-guard

Validate before calling

// Maintain a typed registry so call sites can't mix static/live
const LIVE = new Set(['news','scores']);
function isLive(name: string) { return LIVE.has(name); }
if (isLive(name)) throw new Error(`use getLiveCollection for ${name}`);

Type guard

declare const brand: unique symbol; type LiveName = string & { [brand]: 'live' }; type StaticName = string & { [brand]: 'static' };

Prevention

When it happens

Trigger: Calling getCollection('news') where 'news' is defined with type:'live' in src/live.config.ts; mixing up the two access APIs after migrating a collection to live.

Common situations: Migrating a static collection to a live collection but forgetting to update call sites; copy-pasting getCollection() into a component that handles a live collection; renaming a collection and losing track of its type.

Related errors


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