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

  1. Open the inner error (cause) and safeError.loc to find the exact failing line in the content config.
  2. Fix the syntax/type/schema error in the content config file.
  3. 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

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


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