Skip to content
Latchkey

Bazel "no such package" - Fix Package Resolution in CI

A Bazel label points at a package - a directory with a BUILD file - that Bazel cannot find. Either the directory has no BUILD/BUILD.bazel file, the label path is wrong, or the package lies outside the workspace.

What this error means

A build/test/query aborts with ERROR: no such package '//some/path'. Bazel resolves labels to packages by looking for a BUILD file; when that lookup fails, nothing in that package can be analyzed. Deterministic for a given workspace.

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

Diagnose it: task graph and workspace resolution

Terminal
npx turbo run build --dry-run=json | head -40
npx nx graph --file=graph.json
pnpm -r list --depth -1 2>/dev/null || yarn workspaces list

Common causes

No BUILD file marks the directory as a package

Bazel only treats a directory as a package if it contains a BUILD or BUILD.bazel file. Without one, labels under it do not resolve.

Wrong label path

A typo in the package path, or referencing //services/api when the package is actually //apps/api, yields "no such package".

Package outside the workspace

A path that is not under the workspace root (or is excluded by .bazelignore) is not part of the package tree.

How to fix it

Add a BUILD file to the directory

Create a BUILD file so Bazel recognizes the directory as a package.

BUILD.bazel
# services/api/BUILD.bazel
load("@rules_go//go:def.bzl", "go_binary")

go_binary(name = "api", srcs = ["main.go"])

Verify the label with query

Ask Bazel what packages and targets actually exist before building.

Terminal
bazel query //services/...
bazel query 'kind(rule, //services/api:*)'

How to prevent it

  • Ensure every package directory has a BUILD/BUILD.bazel file.
  • Use bazel query to validate labels before wiring them into CI.
  • Keep .bazelignore from excluding directories you intend to build.

Frequently asked questions

What causes Bazel "no such package"?
There are 3 common causes: no build file marks the directory as a package, wrong label path, and package outside the workspace. Bazel only treats a directory as a package if it contains a BUILD or BUILD.bazel file.
How do I fix Bazel "no such package"?
There are 2 fixes depending on which cause you have: add a build file to the directory and verify the label with query. Work through them in order, since the first is the most common.
What does Bazel "no such package" actually mean?
A build/test/query aborts with ERROR: no such package '//some/path'.
How do I stop Bazel "no such package" happening again?
Ensure every package directory has a BUILD/BUILD.bazel file. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card