Skip to content
Latchkey

Bazel "BUILD file not found" - Fix Missing Packages in CI

Bazel was told to treat a directory as a package but found no BUILD or BUILD.bazel file there. This is the concrete form of "no such package": the marker file that defines a package is absent.

What this error means

A target pattern (e.g. //tools/gen:all) fails with "BUILD file not found in any of the following directories", listing the directory it checked. The directory exists but has no BUILD file, so it is not a package.

Bazel output
ERROR: BUILD file not found in any of the following directories. Add a BUILD
file to a directory to mark it as a package.
 - tools/gen
ERROR: Skipping '//tools/gen:all': no such package 'tools/gen'

Common causes

Directory has no BUILD file

The directory contains sources but no BUILD/BUILD.bazel, so Bazel does not consider it a package and cannot resolve targets in it.

BUILD file not checked in or gitignored

A BUILD file present locally but excluded by .gitignore (or not committed) is absent on the CI checkout, so CI fails where local passes.

How to fix it

Create and commit the BUILD file

Add the BUILD file with the targets that directory should expose, and make sure it is tracked by git.

Terminal
touch tools/gen/BUILD.bazel
git add -f tools/gen/BUILD.bazel   # if a broad .gitignore was hiding it

Check the file is present in CI

  1. Confirm the BUILD file is committed (git ls-files tools/gen).
  2. Check .gitignore does not exclude BUILD/BUILD.bazel.
  3. Run bazel query //tools/gen:all to confirm the package now resolves.

How to prevent it

  • Keep a BUILD/BUILD.bazel file in every package directory and commit it.
  • Add a !BUILD.bazel un-ignore rule if a broad .gitignore could hide it.
  • Validate target patterns with bazel query in CI before building.

Related guides

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