dagger/dagger · error
package name is empty
Error message
package name is empty
What it means
Exactly one package was loaded, but its Name is empty (an unnamed/synthetic package), and codegen does not allow that for this entry point. Per the source comment this happens when loading an empty dir within an existing Go module, or a dir not included in a parent go.work. Pass allowEmpty to accept it.
Source
Thrown at cmd/codegen/generator/go/loader.go:64
return astFile, nil
},
// Print some debug logs with timing information to stdout
Logf: func(format string, args ...any) {
fmt.Printf(format+"\n", args...)
},
}, ".")
if err != nil {
return nil, nil, err
}
switch len(pkgs) {
case 0:
return nil, nil, fmt.Errorf("no packages found in %s", dir)
case 1:
if pkgs[0].Name == "" && !allowEmpty {
// this can happen when:
// - loading an empty dir within an existing Go module
// - loading a dir that is not included in a parent go.work
return nil, nil, fmt.Errorf("package name is empty")
}
return pkgs[0], fset, nil
default:
// this would mean I don't understand how loading '.' works
return nil, nil, fmt.Errorf("expected 1 package, got %d", len(pkgs))
}
}
View on GitHub (pinned to 82ba2681db)
Solutions
- Add a Go source file with a valid `package` clause (e.g. `package main` with `type MyModule struct{}`) to the directory
- If the directory is part of a multi-module workspace, add it to go.work (`go work use ./path`) Check the package clause of existing files is valid and files aren't excluded by build tags
- If this is intentional (client generation into an empty dir), use the code path that sets allowEmpty=true
- Run `go list ./...` in the dir to see what the toolchain itself resolves
Example fix
// before: empty dir inside a module
// after:
cat > main.go <<'EOF'
package main
type MyModule struct{}
func main() {}
EOF
dagger develop Defensive patterns
Strategy: validation
Validate before calling
pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName | packages.NeedTypes}, ".")
if err == nil && len(pkgs) == 1 && pkgs[0].Name == "" {
log.Fatal("dir is an unnamed package: add a .go file or add the module to go.work")
} Prevention
- Write main.go with `package main` before initializing a Dagger module in a Go subdir
- Keep every module dir listed in go.work (`go work use ./dir`)
- Avoid build tags that exclude all files in the module dir
- Verify with `go list ./...` that the package resolves with a name
When it happens
Trigger: loadPackage loads '.' and gets a single package whose packages.Package.Name == "" while allowEmpty is false — i.e. the directory has no compilable Go files of its own but sits inside a module, or the directory isn't part of the active go.work.
Common situations: `dagger init` in a subdir of a Go module with no Go source files yet; developing a module in a directory missing from go.work; all files in the dir excluded by build tags so the loader produces a nameless package; generating a module in a fresh dir before writing any code.
Related errors
- no packages found in %s
- expected 1 package, got %d
- bind workspace module tools: %w
- load workspace arg %q: %w
- workspace port key %q: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/f1833224369ea6f0.
Report an issue: GitHub.