withastro/astro · error · Error

Collection loader for ${name} does not have a load method

Error message

Collection loader for ${name} does not have a load method

What it means

During `sync()`, the content layer iterates collections and, for object-style loaders, calls `collection.loader.load(context)`. If the loader is an object but has no `load` method, the build-time content layer cannot run it and throws. (Function-style loaders are routed to `simpleLoader`; this branch only handles object loaders missing `load`.)

Source

Thrown at packages/astro/src/content/content-layer.ts:343

								_internal: {
									rawData: undefined,
									filePath,
								},
							},
							{ ...collection, schema },
							false,
						),
					loaderName,
					refreshContextData: options?.context,
				});

				if ('loader' in collection) {
					if (typeof collection.loader === 'function') {
						return simpleLoader(collection.loader as CollectionLoader<{ id: string }>, context);
					}

					if (!collection.loader?.load) {
						throw new Error(`Collection loader for ${name} does not have a load method`);
					}

					return collection.loader.load(context);
				}
			}),
		);
		this.#validateReferences(contentConfig.config.collections, logger);
		await fs.mkdir(this.#settings.config.cacheDir, { recursive: true });
		await fs.mkdir(this.#settings.dotAstroDir, { recursive: true });
		const assetImportsFile = new URL(ASSET_IMPORTS_FILE, this.#settings.dotAstroDir);
		await this.#store.writeAssetImports(assetImportsFile);
		const modulesImportsFile = new URL(MODULES_IMPORTS_FILE, this.#settings.dotAstroDir);
		await this.#store.writeModuleImports(modulesImportsFile);
		await this.#store.waitUntilSaveComplete();
		logger.info('Synced content');
		if (this.#settings.config.experimental.contentIntellisense) {
			await this.regenerateCollectionFileManifest();
		}

View on GitHub (pinned to d081033d5f)

Solutions

  1. Use a build-time loader that implements `load` (e.g. `glob()`, `file()`).
  2. If you intend request-time loading, move the collection to `src/live.config.ts` with `defineLiveCollection`.
  3. If writing a custom loader, implement the `load(context)` method.

Example fix

// before
const posts = defineCollection({ loader: { name: 'mine' } /* no load */ });
// after
import { glob } from 'astro/loaders';
const posts = defineCollection({ loader: glob('src/content/posts/*.md') });
Defensive patterns

Strategy: validation

Validate before calling

if ('loader' in collection && typeof collection.loader === 'object' && typeof collection.loader.load !== 'function') {
  throw new Error(`Loader for ${name} needs a load method`);
}

Type guard

function hasLoad(l) { return !!l && typeof l.load === 'function'; }

Prevention

When it happens

Trigger: Defining a build-time collection whose `loader` is an object that does not expose a `load` function — typically a live loader accidentally placed in a build-time collection, or a hand-written incomplete loader.

Common situations: Passing a live loader (with `loadCollection`/`loadEntry` only) to `defineCollection`; writing a custom loader and forgetting to implement `load`; an integration shipping a loader missing the required method.

Related errors


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