Bazel "ERROR: no such target" in CI
Bazel found the package but the name after the colon does not match any rule or file declared in that BUILD file. The message lists the target you asked for and confirms the package was loaded.
What this error means
A build stops with "ERROR: no such target '//foo:bar': target 'bar' not declared in package 'foo'" even though //foo loads fine.
bazel
ERROR: no such target '//foo:bar': target 'bar' not declared in package 'foo'
defined by /home/runner/work/app/app/foo/BUILD.bazel (Tip: use `query "//foo:*"`
to see all the targets in that package)Common causes
The rule name was renamed or removed
The BUILD file no longer declares a rule with that name, so the label points at nothing. A typo in the target name gives the same error.
The file is not exported as a target
You referenced a source file that is not listed in srcs or exported via exports_files, so it is not an addressable target.
How to fix it
List the real targets and fix the label
- Run the query the error suggests to see every target in the package.
- Update the label to a target that actually exists.
- If a file was intended, add it to the rule srcs or exports_files.
Terminal
bazel query "//foo:*"Export a file you need to reference
Declare the file so other packages can address it as a target.
foo/BUILD.bazel
exports_files(["data.json"])How to prevent it
- Keep target names stable, or update all referencing labels when you rename.
- Use
bazel query "//pkg:*"to confirm a target exists before referencing it. - Export files explicitly when they must be visible to other packages.
Related guides
Bazel "ERROR: no such package" in CIFix Bazel "ERROR: no such package" in CI - Bazel could not find a BUILD or BUILD.bazel file for the package p…
Bazel "ERROR: Skipping ...: no such target" pattern in CIFix Bazel "ERROR: Skipping '//...': no such target" in CI - a target pattern on the command line matched a pa…
Bazel "cycle in dependency graph" in CIFix Bazel "ERROR: cycle in dependency graph" in CI - two or more targets depend on each other directly or tra…