Skip to content

Zig Error: root source file struct 'X' has no member named 'Y'

error: root source file struct 'X' has no member named 'Y' means you wrote X.Y, where X is a whole file (like std or one of its parts), and that file has nothing called Y. If you’re following an older tutorial, this is the error you’ll see most: root source file struct 'std' has no member named 'io' is what Zig 0.16 and 0.17 say to the hello world from almost every older guide. The fix is usually to find the new name. This page has a table of the most common ones. For the other errors in this series, see Zig Errors Explained.

const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {s}!\n", .{"world"});
}
main.zig:4:24: error: root source file struct 'std' has no member named 'io'
const stdout = std.io.getStdOut().writer();
^~
.../lib/std/std.zig:1:1: note: struct declared here
pub const AutoHashMap = hash_map.AutoHashMap;
^~~

The caret points at io, the name that’s missing. The note points at the first line of std.zig, the file Zig searched. That line has nothing to do with your mistake; it’s just where the file starts.

In Zig, every file is a struct. When you write const std = @import("std");, std becomes a struct whose members are everything the file std.zig declares with pub. “Root source file struct” is the compiler’s way of saying “the struct made from a whole file”. The same goes for std.fs, std.heap or std.time: each is its own file, so the message names whichever one you looked in, like root source file struct 'fs' has no member named 'cwd'.

So the error means one of three things: the name was renamed or removed (very common, Zig is still pre-1.0), you misspelled it, or it’s in your own file and isn’t pub.

Fix 1: Use the new name from the current Zig

Section titled “Fix 1: Use the new name from the current Zig”

Zig 0.16 moved all I/O into a new std.Io interface, and a lot of older names went away. Here’s the hello world above, written for 0.17.1:

const std = @import("std");
pub fn main(init: std.process.Init) !void {
var buf: [256]u8 = undefined;
var w = std.Io.File.stdout().writer(init.io, &buf);
const stdout = &w.interface;
try stdout.print("Hello, {s}!\n", .{"world"});
try stdout.flush();
}

Output:

Hello, world!

Two new ideas: main receives init, which carries init.io (the thing that does the actual I/O), and the writer has a buffer, so you call flush() at the end. Forget flush and nothing is printed. Zig Output walks through it slowly. For quick debug prints, std.debug.print still works as before.

These are the old names people hit most, all checked on 0.17.1:

Old code Error says Now
std.io.getStdOut() 'std' has no member named 'io' std.Io.File.stdout(), with init.io. See Zig Output
std.fs.cwd() 'fs' has no member named 'cwd' std.Io.Dir.cwd(), methods take io. See Zig File I/O
std.heap.GeneralPurposeAllocator(.{}) 'heap' has no member named 'GeneralPurposeAllocator' init.gpa. See Zig Allocators
std.process.argsAlloc(...) 'process' has no member named 'argsAlloc' init.minimal.args.toSlice(arena). See Zig CLI Arguments
std.os.getenv("X") 'os' has no member named 'getenv' init.environ_map.get("X"). See Zig Environment Variables
std.time.sleep(ns), std.Thread.sleep(ns) 'time' has no member named 'sleep' try io.sleep(.fromMilliseconds(10), .awake)
std.time.Timer, std.time.timestamp() 'time' has no member named 'Timer' std.Io.Timestamp.now(io, .awake). See Zig Performance
std.Thread.Mutex 'Thread' has no member named 'Mutex' std.Io.Mutex. See Zig Shared State
std.Thread.Pool 'Thread' has no member named 'Pool' io.async(...), io.concurrent(...). See Zig Async
std.rand 'std' has no member named 'rand' std.Random

For anything not in this table, the release notes list what moved: 0.16.0 for the big I/O change, and 0.17.0 for the latest one. Searching the standard library source (in lib/std/ next to your zig binary) for the old name’s job often finds the new one quickly.

Not every miss is a rename. std.debug.prnt gives the same kind of error:

const std = @import("std");
pub fn main() void {
std.debug.prnt("hi\n", .{});
}
main.zig:4:14: error: root source file struct 'debug' has no member named 'prnt'
std.debug.prnt("hi\n", .{});
~~~~~~~~~^~~~~

Names are case sensitive too: std.Io (the new interface) and std.io (gone) are different names. Typing std.debug. in an editor with ZLS shows the list of members, which settles it.

With your own files, the member may exist but be private. A function in math.zig without pub gives a clearer message:

main.zig:5:36: error: 'add' is not marked 'pub'
std.debug.print("{d}\n", .{math.add(2, 3)});
~~~~^~~~
math.zig:1:1: note: declared here
fn add(a: i32, b: i32) i32 {
^~~~~~~~~~~~~~~~~~~~~~~~~~

Write pub fn add(...) in math.zig. If the message says has no member instead, the name really isn’t in that file: check that you imported the file you meant. Zig Modules covers imports and pub.

Constants and functions declared inside a struct are members too, and a missing one gives a shorter version of this message:

const Point = struct {
x: i32,
y: i32,
};
pub fn main() void {
const o = Point.origin;
_ = o;
}
main.zig:7:20: error: struct 'main.Point' has no member named 'origin'
const o = Point.origin;
~~~~~^~~~~~~
main.zig:1:15: note: struct declared here
const Point = struct {
^~~~~~

Add it inside the struct (pub const origin: Point = .{ .x = 0, .y = 0 };) or fix the name.

  • Code or tutorials for Zig 0.15 and older, especially anything with std.io, std.fs or GeneralPurposeAllocator.
  • AI-generated Zig code, which often mixes APIs from several old versions.
  • Typos in long std. paths.
  • Your own files, when a declaration isn’t pub or the import points at the wrong file.

This program was written for an older Zig. Make it build on 0.17.1 and print 5 files, using a buffered stdout writer.

const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
const count: u32 = 5;
try stdout.print("{d} files\n", .{count});
}

Hint: main needs init for init.io, and the writer needs a buffer and a flush().

Show solution
const std = @import("std");
pub fn main(init: std.process.Init) !void {
var buf: [64]u8 = undefined;
var w = std.Io.File.stdout().writer(init.io, &buf);
const stdout = &w.interface;
const count: u32 = 5;
try stdout.print("{d} files\n", .{count});
try stdout.flush();
}

Output:

5 files

std.Io.File.stdout() replaces std.io.getStdOut(). Take the address of w.interface (copying it compiles but breaks the writer), and flush before main returns.

  • Every file is a struct, so std, std.fs and your own files have members.
  • The error means the file has no pub declaration with that name.
  • Most often it’s old code: std.io, std.fs.cwd, GeneralPurposeAllocator, argsAlloc and friends moved in 0.16 and 0.17.
  • Otherwise check the spelling and case (std.Io, not std.io).
  • In your own files, declarations need pub to be seen from other files.

Next up: expected N argument(s), found M, the error for calling a function with the wrong number of arguments.

Quick check

1. What does "root source file struct" mean?
2. You copied std.io.getStdOut() from a tutorial and get this error. What is the most likely cause?
3. Your main.zig calls utils.trim(...), and utils.zig has fn trim. What is missing?