withastro/astro · error · AstroError

GenerateContentTypesError

GenerateContentTypesError

Error message

`astro sync` command failed to generate content collection types: ${errorMessage}.

What it means

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.

Solutions

  1. Read the full error output: the message contains the underlying error's text and `cause` carries the original error - fix that first.
  2. Run `npx astro sync` alone to reproduce the failure quickly without a dev/build session.
  3. Check src/content/config.ts for syntax errors, a missing default export, or invalid loader options (glob pattern/base, file loader entry).
  4. 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.
  5. Delete the generated .astro directory (stale types) and re-run `astro sync`.

Example fix

// before - src/content/config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/data' }), // no such directory
});
export default { blog };

// after
const blog = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
});
export default { blog };
Defensive patterns

Strategy: try-catch

Validate before calling

// CI: surface content-config breakage before deploy
// package.json scripts: "ci": "astro sync && astro build"
// `astro sync` re-runs type generation and fails loudly on any config or loader error.

Try / catch

import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
const run = promisify(execFile);
try {
  await run('npx', ['astro', 'sync']);
} catch (e) {
  // e.stderr contains 'GenerateContentTypesError' plus the underlying cause
  console.error(e.stderr ?? e.message);
  process.exit(1);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of withastro/astro@e294953aa8 (2026-08-18). Data as JSON: /api/errors/66f69fba845a52a1. Report an issue: GitHub.

Appendix: 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 e294953aa8)