{"record":{"id":"0885c1b5fc6495de","repo":"withastro/astro","slug":"collection-loader-for-name-does-not-have-a-load","errorCode":null,"errorMessage":"Collection loader for ${name} does not have a load method","messagePattern":"Collection loader for (.+?) does not have a load method","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/content-layer.ts","lineNumber":343,"sourceCode":"\t\t\t\t\t\t\t\t_internal: {\n\t\t\t\t\t\t\t\t\trawData: undefined,\n\t\t\t\t\t\t\t\t\tfilePath,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ ...collection, schema },\n\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t),\n\t\t\t\t\tloaderName,\n\t\t\t\t\trefreshContextData: options?.context,\n\t\t\t\t});\n\n\t\t\t\tif ('loader' in collection) {\n\t\t\t\t\tif (typeof collection.loader === 'function') {\n\t\t\t\t\t\treturn simpleLoader(collection.loader as CollectionLoader<{ id: string }>, context);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!collection.loader?.load) {\n\t\t\t\t\t\tthrow new Error(`Collection loader for ${name} does not have a load method`);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn collection.loader.load(context);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tthis.#validateReferences(contentConfig.config.collections, logger);\n\t\tawait fs.mkdir(this.#settings.config.cacheDir, { recursive: true });\n\t\tawait fs.mkdir(this.#settings.dotAstroDir, { recursive: true });\n\t\tconst assetImportsFile = new URL(ASSET_IMPORTS_FILE, this.#settings.dotAstroDir);\n\t\tawait this.#store.writeAssetImports(assetImportsFile);\n\t\tconst modulesImportsFile = new URL(MODULES_IMPORTS_FILE, this.#settings.dotAstroDir);\n\t\tawait this.#store.writeModuleImports(modulesImportsFile);\n\t\tawait this.#store.waitUntilSaveComplete();\n\t\tlogger.info('Synced content');\n\t\tif (this.#settings.config.experimental.contentIntellisense) {\n\t\t\tawait this.regenerateCollectionFileManifest();\n\t\t}","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/content/content-layer.ts#L325-L361","documentation":"During content-layer sync (build or dev), each collection's loader must be either a function (treated as a simple loader) or an object with a `load()` method. This Error is thrown from ContentLayer.sync when a collection's `loader` object has no `load` function — typically a live or malformed loader that reached the sync stage without going through defineCollection's config-time validation.","triggerScenarios":"A collections config built programmatically (objects assembled without `defineCollection`, or cast to bypass its checks) whose loader implements `loadEntry`/`loadCollection` but not `load`; a hand-written loader missing the `load` method; a `loader: {}` typo.","commonSituations":"Configs constructed dynamically or imported from JS modules that skip defineCollection validation; switching a loader type while a stale build cache references the old shape; custom loaders authored without the `load` method.","solutions":["Implement `load(context)` on the loader object — the build-time loader contract","If the loader is actually a live loader (loadEntry/loadCollection), move that collection to `src/live.config.ts` with `defineLiveCollection`","If the loader is a plain function, pass it directly as `loader` — functions are wrapped into simple loaders automatically"],"exampleFix":"// before\nconst loader = { loadEntry, loadCollection }; // no load()\ncollections.posts = { loader };\n\n// after\nconst loader = {\n  async load(context) {\n    // read entries and store them via context.store\n  },\n};\ncollections.posts = defineCollection({ loader });","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isBuildTimeLoader(loader) {\n  return typeof loader === 'function' || typeof loader?.load === 'function';\n}\n\nif (!isBuildTimeLoader(collection.loader)) {\n  // object without load() — either implement load() or move the collection to live.config.ts\n  throw new TypeError('collection loader must be a function or an object with load()');\n}","tryCatchPattern":null,"preventionTips":["Always define collections through `defineCollection` so loader shape is validated at config load, not at sync time","Type loaders against the content-layer loader interface (a `load(context)` method) in custom code","When switching a collection between live and build-time, move the whole definition between config files — never just the loader"],"tags":["content-collections","content-layer","loaders","build"],"backgroundTag":"incompatible-loader-type","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}