withastro/astro · error · AstroError
GenerateContentTypesError
GenerateContentTypesError
Error message
`astro sync` command failed to generate content collection types: ${errorMessage}. What it means
`astro sync` generates TypeScript types for content collections; it wraps any failure as AstroError code GenerateContentTypesError, attaching the original error as cause and a hint pointing at your content config file. The message embeds safeError.message and uses safeError.loc as location.
Source
Thrown at packages/astro/src/core/sync/index.ts:352
const contentPaths = getContentPaths(
settings.config,
fs,
settings.config.legacy?.collectionsBackwardsCompat,
);
if (contentPaths.config.exists) {
const matches = /\/(src\/.+)/.exec(contentPaths.config.url.href);
if (matches) {
configFile = matches[1];
}
}
} catch {
// ignore
}
const hint = AstroUserError.is(e)
? e.hint
: AstroErrorData.GenerateContentTypesError.hint(configFile);
throw new AstroError(
{
...AstroErrorData.GenerateContentTypesError,
hint,
message: AstroErrorData.GenerateContentTypesError.message(safeError.message),
location: safeError.loc,
},
{ cause: e },
);
}
}
View on GitHub (pinned to d081033d5f)
Solutions
- Open the inner error (cause) and safeError.loc to find the exact failing line in the content config.
- Fix the syntax/type/schema error in the content config file.
- Re-run `astro sync` to confirm types generate cleanly.
Defensive patterns
Strategy: try-catch
Validate before calling
async function runSync() {
try {
// import the content config to surface errors before astro sync runs
await import('./src/content.config.ts');
} catch (e) {
throw new Error('Content config error before sync: ' + e.message);
}
} Try / catch
try {
await sync();
} catch (e) {
if (e.name === 'GenerateContentTypesError' && e.cause) {
console.error('Underlying failure:', e.cause);
// fix the content/config error, then re-run `astro sync`
} else throw e;
} Prevention
- Keep src/content.config.ts syntactically valid and type-checked.
- Run `astro sync` in CI to catch content config regressions.
- Inspect the wrapped error's cause and location for the true source.
When it happens
Trigger: A syntax or type error in src/content.config.ts (or src/content/config.ts); a bad collection schema (zod); an import that fails to resolve inside the config; an exception thrown while executing the config module.
Common situations: Editing the content config; upgrading the Content Layer API / collections API between versions; a typo in a collection name or schema field; a renamed import.
Related errors
- Collection loader for ${name} does not have a load method
- UnknownFilesystemError
- **${rootRelativePath}** contains invalid content: ${validati
- [RSS] You can only glob entries within 'src/pages/' when pas
- [astro:actions] `defineAction()` unexpectedly used on the cl
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/66f69fba845a52a1.
Report an issue: GitHub.