Astro "Cannot find module 'astro:content'" type error in CI
The astro:content module (and its generated types in .astro) is created by astro sync. When a clean runner runs astro check or tsc before sync, the virtual module is missing and TypeScript or the build cannot resolve it.
What this error means
astro check / tsc fails with "Cannot find module 'astro:content' or its corresponding type declarations" referencing files that call getCollection or defineCollection.
src/pages/blog/index.astro:2:31 - error TS2307: Cannot find module 'astro:content'
or its corresponding type declarations.
2 import { getCollection } from 'astro:content';Common causes
astro sync did not run before the check
The generated .astro types, including astro:content, are produced by astro sync; running astro check or tsc first leaves the virtual module unresolved.
A stale or missing .astro types directory
The generated types are git-ignored and never regenerated on the clean checkout, so the module is absent in CI.
How to fix it
Run astro sync before the type check
- Run
astro syncto generate the content types. - Then run
astro checkor yourtscstep. - Keep this order in the CI job.
npx astro sync
npx astro checkBuild, which syncs implicitly
A full astro build runs sync as part of the build, so the virtual module exists for the build itself.
npx astro buildHow to prevent it
- Run
astro syncbefore any standalone type check. - Do not commit or depend on a stale
.astrotypes directory. - Keep content collection config valid so sync can generate types.