Skip to content
Latchkey

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.

astro
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

  1. Run astro sync to generate the content types.
  2. Then run astro check or your tsc step.
  3. Keep this order in the CI job.
Terminal
npx astro sync
npx astro check

Build, which syncs implicitly

A full astro build runs sync as part of the build, so the virtual module exists for the build itself.

Terminal
npx astro build

How to prevent it

  • Run astro sync before any standalone type check.
  • Do not commit or depend on a stale .astro types directory.
  • Keep content collection config valid so sync can generate types.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →