If you build sites with Astro, you might have run into an error like "The collection ‘xxx’ does not exist or is empty" when building in CI environments like Cloud Build […]
The cause of this issue can be elusive because it works fine locally and only fails during builds in external CI environments like Cloud Build.
Here, based on a real-world example, we explain the root cause of the issue and how to resolve it.
Issue
On Cloud Build, a build error occurs indicating that an Astro Content Collection (e.g., column, news) "does not exist" or "is empty."
Root cause
Astro reads Content Collections and automatically generates types for them. However, in CI environments, failure to run this type generation command (astro sync) causes the collection to fail to load at build time, resulting in an error.
Solution
Simply adding astro sync explicitly to your Cloud Build YAML will resolve the issue!
Example: cloudbuild.yaml
steps:
- name: "node"
entrypoint: "npm"
args: ["install"]
- name: "node"
entrypoint: "npx"
args: ["astro", "sync"] # これを追加
- name: "node"
entrypoint: "npm"
args: ["run", "build"]
- name: "gcr.io/cloud-builders/gsutil"
args: ["-m", "rsync", "-d", "-r", "dist", "gs://your-bucket"]
Conclusion
Building Astro in CI/CD can introduce challenges due to minor discrepancies like this, but once you understand the cause, the fix is straightforward.
If you are running into "Content Collections not loading only on Cloud Build," please give the steps above a try!








