Skip to content
Putting technology to work.
Insights to guide decisions and action.

Search articles

How to fix Astro build errors

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!

Share this articleXFacebook
Rui Teruya

Former corporate league baseball player and founder of an IT venture. Founded the company with the drive to ride the fast-moving waves of the world and deliver truly valuable services to society.

Turn this article's theme into your company's next step

Concrete steps forward for your organization.

We organize your desired architecture, legacy systems, and operational requirements to formulate your next steps toward execution.

  • Desired architecture
  • Integration with existing environments
  • Operational requirements
Consult on development & operations initiatives

You can consult with us from the initial conceptual stage. Details from this article will be carried over to the inquiry form.

Receive the latest articles by email