Skip to content
Latchkey

Zig "dependency not found" in build.zig.zon in CI

When build.zig calls b.dependency("name", ...), Zig looks that name up in the .dependencies table of build.zig.zon. If it is not declared there, the build fails before fetching anything.

What this error means

zig build fails with "error: dependency X not found" pointing at the b.dependency call, because build.zig.zon has no matching entry.

zig
build.zig:12:32: error: dependency 'mecha' not found
    const mecha = b.dependency("mecha", .{});

Common causes

The dependency is not in build.zig.zon

b.dependency("name") requires a key of the same name under .dependencies in the manifest; a missing or misnamed key fails the lookup.

The manifest was not added with zig fetch

The dependency was referenced in build.zig but never registered in build.zig.zon with zig fetch --save.

How to fix it

Add the dependency to the manifest

  1. Run zig fetch --save with the dependency URL to add it to build.zig.zon.
  2. Confirm the key matches the name used in b.dependency(...).
  3. Commit build.zig.zon so CI has the declaration.
Terminal
zig fetch --save https://github.com/Hejsil/mecha/archive/refs/tags/0.9.0.tar.gz

Align the name in build.zig with the manifest key

The string passed to b.dependency must equal the key under .dependencies exactly.

build.zig.zon
.dependencies = .{
    .mecha = .{ .url = "...", .hash = "..." },
},

How to prevent it

  • Register dependencies with zig fetch --save so the manifest stays in sync.
  • Keep the b.dependency name identical to the manifest key.
  • Commit build.zig.zon alongside build.zig changes.

Related guides

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