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
- Use a build-time loader that implements `load` (e.g. `glob()`, `file()`).
- If you intend request-time loading, move the collection to `src/live.config.ts` with `defineLiveCollection`.
- 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
- Use build-time loaders from `astro/loaders` (`glob`, `file`) for build-time collections.
- Ensure custom object loaders implement `load`.
- Validate the loader shape in tests before running `astro sync`.
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
- Live content collections must be defined in "src/live.config
- ContentLoaderReturnsInvalidId
- ContentLoaderInvalidDataError
- ExpectedImageOptions
- FileGlobNotSupported
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/0885c1b5fc6495de.
Report an issue: GitHub.