Skip to content
Latchkey

Bazel "Failed to load Starlark extension" in CI

A load() statement referenced a .bzl file by label, and Bazel could not resolve it. The extension label points at a repository or path that is missing, so loading fails before analysis.

What this error means

A build fails with "ERROR: Failed to load Starlark extension '@repo//path:file.bzl'" and a note that the repository or file cannot be found.

bazel
ERROR: Failed to load Starlark extension '@rules_foo//foo:defs.bzl'.
Cycle in the load graph or the repository '@rules_foo' could not be resolved.
It may not have been defined in MODULE.bazel or WORKSPACE.

Common causes

The repository was never declared or fetched

The @rules_foo repo in the load label is not defined in MODULE.bazel/WORKSPACE, so Bazel cannot find the .bzl file.

A wrong label path to the extension

The path or file name in the load label is incorrect, so the .bzl file does not exist at that location.

How to fix it

Declare the repository the extension lives in

  1. Add the missing module or repo to MODULE.bazel (or WORKSPACE).
  2. Confirm the load label path matches a real .bzl file in that repo.
  3. Re-run so the extension resolves and loads.
MODULE.bazel
bazel_dep(name = "rules_foo", version = "1.2.0")

Correct the load label

Fix the repository name and path so the label points at an existing .bzl file.

foo/BUILD.bazel
load("@rules_foo//foo:defs.bzl", "foo_binary")

How to prevent it

  • Declare every repository referenced by a load statement.
  • Keep load label paths in sync with the extension file locations.
  • Run analysis in CI so unresolved loads fail before deploy.

Related guides

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