Problem when importing modules

i’m working with two modules (zig-cli and zig-yaml) – both of which i’ve cloned, built, and tested with my recent version of zig build

following protocol, i then prepared a build.zig.zon file with the appropriate dependencies:

    .dependencies = .{
        .@"zig-cli" = .{
            .url = "",
            .hash = "122092c8a98897c6e0946f39930ce7b48162bd62400834104c95c871f53887377aa7",
        .@"zig-yaml" = .{
            .url = "",
            .hash = "122084941d6e06491a85e1356c7cca24a078103d34155e34a10a16a53f420d6bc37b",

i verifed these hashes using zig fetch --save

in my build.zig file, i have the following loop which adds the modules as dependencies of my main program:

    const DEPS: [2][]const u8 = .{

    for (DEPS) |name| {
        std.debug.print("name = {s}\n", .{name});
        const dep = b.dependency(name, .{
            .target = target,
            .optimize = optimize,
        exe.root_module.addImport(name, dep.module(name));

everything works fine with zig-cli, but for some reason zig-yaml causes the following failure from zig build

$ zig build
name = zig-cli
name = zig-yaml
thread 14488 panic: unable to find module 'zig-yaml'
C:\tools\zig-dev\lib\std\debug.zig:434:22: 0xf60965 in panicExtra__anon_15732 (build.exe.obj)
    std.builtin.panic(msg, trace, ret_addr);
C:\tools\zig-dev\lib\std\debug.zig:409:15: 0xf348fc in panic__anon_15228 (build.exe.obj)
    panicExtra(null, null, format, args);
C:\tools\zig-dev\lib\std\Build.zig:1804:18: 0xf0ad89 in module (build.exe.obj)
            panic("unable to find module '{s}'", .{name});
C:\Users\biosb\gitrepos\zigem\build.zig:24:51: 0xebf859 in build (build.exe.obj)
        exe.root_module.addImport(name, dep.module(name));
C:\tools\zig-dev\lib\std\Build.zig:2000:33: 0xe9e2c5 in runBuild__anon_8779 (build.exe.obj)
        .Void =>,
C:\tools\zig-dev\lib\compiler\build_runner.zig:310:29: 0xe9936c in main (build.exe.obj)
        try builder.runBuild(root);
C:\tools\zig-dev\lib\std\start.zig:350:53: 0xea02ec in WinStartup (build.exe.obj);
???:?:?: 0x7ffc4d1d7343 in ??? (KERNEL32.DLL)
???:?:?: 0x7ffc4d6a26b0 in ??? (ntdll.dll)
error: unable to read results of configure phase from 'C:\Users\biosb\gitrepos\zigem\zig-cache\tmp\ff50a1d5f14c31f7': FileNotFound

main.zig trivially imports these two modules:

const cli = @import("zig-cli");
const yaml = @import("zig-yaml");

as the category says, HELP !!!

If you look at this zig-yaml/build.zig at 9308a64224f32184500d8a8178be0066443d65bc · kubkon/zig-yaml · GitHub the module is just called “yaml”.

So you need dep.module("yaml").

However here zig-cli/build.zig at beff935fe77a0ed794e8727d48e7780485abb880 · sam701/zig-cli · GitHub it is called “zig-cli”.

If you want to keep the code you could just call your dependency “yaml” and use “yaml” for everything.

live and learn… back in the “good ol’ days” of java and OSGI bundles, tooling enforced a much stricter correspondence between logical names and the physical location of the artifact…

i’m admitedly new to this world… but having found a git repo named zig-cli with a module named zig-cli, you’d think a git repo named zig-yaml

i assume there’s a roadmap for something like npm in zig-land??? at least there the name of the package/module is front-and-center…

but thanks again to y’all for helping me up the learning curve :pray:

1 Like

One package could have several modules/artifacts, so in that case you would have to find out the name of it anyway.

But I guess it would be good to come up with conventions, or create tooling that easily shows available modules/artifacts from a dependency.

Zig package management is decentralized, however there is a topic about package discovery Package index service.