“Failed to generate content types” means astro sync could not build the TypeScript types for your content collections. It is a wrapper: the real cause is the error message inside it, usually a syntax error in src/content.config.ts, a broken import in that file, or a content file that cannot be parsed. Fix that underlying error and run npx astro sync again.
Key Takeaways
- The text after “failed to generate content collection types:” is the real error.
astro syncalso runs at the start ofastro dev,astro buildandastro check.- Most cases are a typo or a bad import in
src/content.config.ts.- A malformed frontmatter or data file can also stop type generation.
- Run
npx astro syncalone to see the error without the rest of the build.
The error
Failed to generate content types.
`astro sync` command failed to generate content collection types: Unexpected token, expected "," (14:4).
Hint: This error is often caused by a syntax error inside your content, or your content configuration file. Check your src/content.config.ts file for typos.
The part after the colon changes every time. It is the original error message, and the location (line and column) usually points at the line to fix.
Why it happens
Before every dev server start and build, Astro runs a sync step: it loads src/content.config.ts, runs each collection’s loader, and writes types to the .astro/ folder so getCollection('blog') is typed. If anything in that chain throws, Astro reports it as this error. Common causes:
- Syntax error in the config. A missing comma or bracket in a
z.object({ ... }). - Bad import. Importing
zfrom a path that no longer exists, or a helper file with its own error. - Loader failure. A custom loader that throws, or a
file()loader pointing at a missing or invalid JSON or YAML file. - Unparseable content. Frontmatter with broken YAML in one Markdown file.
Fix the config file
Read the wrapped message and go to the line it names. A typical mistake:
// src/content.config.ts (broken)
const blog = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/blog' })
schema: z.object({ title: z.string() }),
});
The comma after the loader line is missing. The corrected file, with current imports:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
schema: z.object({ title: z.string() }),
});
export const collections = { blog };
Import z from astro/zod; the re-export from astro:content is deprecated.
Fix a content or data file
If the config looks fine, the message often names a file under src/content/ or your data folder. Check its frontmatter or JSON for unclosed quotes, tabs in YAML, or a stray ---. The frontmatter parse error tip covers YAML mistakes in detail.
Rerun sync
# Terminal
npx astro sync
If it passes, start the dev server again. If it still fails with no clear cause, delete the generated folder and retry, which clears stale types:
# Terminal
rm -rf .astro
npx astro sync
The astro sync command tip explains what the command generates, and the content collections docs walk through a working config. The official CLI reference lists its flags. Blog themes in our Blog & Editorial category ship with a working src/content.config.ts you can compare against.
FAQ
What does astro sync do?
It generates TypeScript types for content collections, environment variables and other Astro modules into the .astro/ folder. Astro runs it automatically before dev, build and check.
Why does astro dev fail with failed to generate content types?
Because dev runs the same sync step on startup. Fix the error shown after “failed to generate content collection types:” and restart.
Is it safe to delete the .astro folder?
Yes. It holds generated files such as type declarations, and Astro recreates it on the next sync, dev or build.