{"record":{"id":"66f69fba845a52a1","repo":"withastro/astro","slug":"generatecontenttypeserror","errorCode":"GenerateContentTypesError","errorMessage":"`astro sync` command failed to generate content collection types: ${errorMessage}.","messagePattern":"`astro sync` command failed to generate content collection types: (.+?)\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/sync/index.ts","lineNumber":352,"sourceCode":"\t\t\tconst contentPaths = getContentPaths(\n\t\t\t\tsettings.config,\n\t\t\t\tfs,\n\t\t\t\tsettings.config.legacy?.collectionsBackwardsCompat,\n\t\t\t);\n\t\t\tif (contentPaths.config.exists) {\n\t\t\t\tconst matches = /\\/(src\\/.+)/.exec(contentPaths.config.url.href);\n\t\t\t\tif (matches) {\n\t\t\t\t\tconfigFile = matches[1];\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\n\t\tconst hint = AstroUserError.is(e)\n\t\t\t? e.hint\n\t\t\t: AstroErrorData.GenerateContentTypesError.hint(configFile);\n\t\tthrow new AstroError(\n\t\t\t{\n\t\t\t\t...AstroErrorData.GenerateContentTypesError,\n\t\t\t\thint,\n\t\t\t\tmessage: AstroErrorData.GenerateContentTypesError.message(safeError.message),\n\t\t\t\tlocation: safeError.loc,\n\t\t\t},\n\t\t\t{ cause: e },\n\t\t);\n\t}\n}\n","sourceCodeStart":334,"sourceCodeEnd":363,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/core/sync/index.ts#L334-L363","documentation":"Astro generates TypeScript types for your content collections during `astro sync`, which also runs at the start of `astro dev` and `astro build`. This AstroError wraps any failure in that step: the message embeds the underlying error's message, `cause` holds the original error, and the hint points at your content config file (usually src/content/config.ts). It means the collection config or one of its loaders/schema broke, not that the type generator itself is buggy.","triggerScenarios":"Running `astro sync`, `astro dev`, or `astro build` when src/content/config.ts throws while loading (syntax error, bad export, invalid loader options); a glob()/file() loader whose base directory or pattern is wrong; a custom or CMS loader that throws while reading entries; using content-layer APIs that changed across a major Astro upgrade.","commonSituations":"A typo or missing default export in the content config; a glob pattern pointing at a renamed/moved directory; upgrading Astro across the legacy-collections to Content Layer API transition; a stale or corrupted .astro directory of generated types.","solutions":["Read the full error output: the message contains the underlying error's text and `cause` carries the original error - fix that first.","Run `npx astro sync` alone to reproduce the failure quickly without a dev/build session.","Check src/content/config.ts for syntax errors, a missing default export, or invalid loader options (glob pattern/base, file loader entry).","If a custom or third-party loader throws, reduce the config to one minimal collection and re-add collections one by one to isolate the failure.","Delete the generated .astro directory (stale types) and re-run `astro sync`."],"exampleFix":"// before - src/content/config.ts\nimport { defineCollection } from 'astro:content';\nimport { glob } from 'astro/loaders';\nconst blog = defineCollection({\n  loader: glob({ pattern: '**/*.md', base: './src/data' }), // no such directory\n});\nexport default { blog };\n\n// after\nconst blog = defineCollection({\n  loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),\n});\nexport default { blog };","handlingStrategy":"try-catch","validationCode":"// CI: surface content-config breakage before deploy\n// package.json scripts: \"ci\": \"astro sync && astro build\"\n// `astro sync` re-runs type generation and fails loudly on any config or loader error.","typeGuard":null,"tryCatchPattern":"import { execFile } from 'node:child_process';\nimport { promisify } from 'node:util';\nconst run = promisify(execFile);\ntry {\n  await run('npx', ['astro', 'sync']);\n} catch (e) {\n  // e.stderr contains 'GenerateContentTypesError' plus the underlying cause\n  console.error(e.stderr ?? e.message);\n  process.exit(1);\n}","preventionTips":["Run `astro sync` in CI so content-config and loader failures fail the pipeline, not a production build.","Keep src/content/config.ts minimal and typed; validate loader options against the astro/loaders docs for your version.","After major Astro upgrades, re-read the content collections migration notes before keeping old configs."],"tags":["content-collections","codegen","sync","typescript"],"backgroundTag":"code-generation-failed","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}