Skip to content
Latchkey

Bazel "this rule is missing dependency declarations" (strict deps) in CI

Bazel enforces strict deps: a target may only use files provided by its direct dependencies. It found a file consumed by the rule that comes from a target not listed in deps, and names both the file and the dependency to add.

What this error means

A build fails with "this rule is missing dependency declarations for the following files included by ..." and often a hint like "Please add the following dependencies: //bar:baz".

bazel
ERROR: /home/runner/work/app/app/foo/BUILD.bazel:3:11: this rule is missing
dependency declarations for the following files included by 'foo/a.cc':
  'bar/baz.h'
Please add the following dependencies: //bar:baz

Common causes

A transitive dependency was used directly

The file comes from a target you get transitively, but strict deps requires it as a direct entry in this rule deps.

A new include without a matching deps edge

Code added an include from another package without updating deps, so the file is used but undeclared.

How to fix it

Add the suggested dependency

  1. Copy the label from the "Please add the following dependencies" hint.
  2. Add it to the target deps in the BUILD file.
  3. Re-run so the direct dependency now covers the used file.
foo/BUILD.bazel
cc_library(
    name = "lib",
    srcs = ["a.cc"],
    deps = ["//bar:baz"],
)

Automate deps edits with a fixer

For large monorepos, a build-file fixer can add missing deps from the compiler-reported includes automatically.

Terminal
bazel build //foo:lib --experimental_strict_java_deps=error

How to prevent it

  • Declare a direct deps edge for every file a target uses.
  • Do not rely on transitive dependencies to satisfy includes.
  • Keep strict deps set to error so gaps fail fast in CI.

Frequently asked questions

What causes ""missing dependency declarations""?
The file comes from a target you get transitively, but strict deps requires it as a direct entry in this rule deps.
How do I fix "missing dependency declarations"?
Add the suggested dependency

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card