goreleaser/goreleaser · error
ko: %s does not contain a valid local import path (%s) for d
Error message
ko: %s does not contain a valid local import path (%s) for directory (%s): %w
What it means
buildBuildOptions uses golang.org/x/tools/go/packages to resolve ko.main (or "." if empty) into a local import path relative to ko.working_dir; packages.Load itself errored, so goreleaser reports that the directory does not contain a valid local import path, wrapping the underlying load error.
Source
Thrown at internal/pipe/ko/ko.go:403
func buildBuildOptions(ctx *context.Context, cfg config.Ko) (*buildOptions, error) {
localImportPath := cfg.Main
if localImportPath == "" {
// ko.main is optional, and go1.27+ rejects an empty package pattern.
localImportPath = "."
}
dir := filepath.Clean(cfg.WorkingDir)
if dir == "." {
dir = ""
}
pkgs, err := packages.Load(&packages.Config{
Mode: packages.NeedName,
Dir: dir,
}, localImportPath)
if err != nil {
return nil, fmt.Errorf(
"ko: %s does not contain a valid local import path (%s) for directory (%s): %w",
cfg.ID, localImportPath, cfg.WorkingDir, err,
)
}
if len(pkgs) != 1 {
return nil, fmt.Errorf(
"ko: %s results in %d local packages, only 1 is expected",
cfg.ID, len(pkgs),
)
}
opts := &buildOptions{
importPath: pkgs[0].PkgPath,
workingDir: cfg.WorkingDir,
bare: cfg.Bare,
preserveImportPaths: cfg.PreserveImportPaths,
baseImportPaths: cfg.BaseImportPaths,View on GitHub (pinned to f5edd73956)
Solutions
- Run `go list ./...` (or `go list <pattern>`) in ko.working_dir to reproduce and see the raw error
- Fix ko.main to a valid package pattern (e.g. ./cmd/app) or remove it to default to "."
- Ensure go.mod exists in working_dir
- Run `go mod tidy` if go.sum/module errors appear
Example fix
// before kos: - main: ./ap // after kos: - main: ./cmd/app
Defensive patterns
Strategy: validation
Validate before calling
cd "$(yq '.kos[0].working_dir // "."' .goreleaser.yaml)" && go list "$(yq '.kos[0].main // "."' .goreleaser.yaml)" >/dev/null || echo 'ko.main unresolvable'
Prevention
- Run `go list <ko.main>` in CI before release
- Keep go.mod/go.sum committed and tidy
- Prefer explicit package dirs over broad patterns
When it happens
Trigger: packages.Load fails for the given pattern/dir: no Go module in working_dir, invalid pattern syntax, missing go.sum entries, or tooling errors loading the package graph.
Common situations: ko.main points at a directory with no Go files; running outside a module (no go.mod); corrupted module cache; typo in ko.main pattern like "./cmmd".
Related errors
- ko: %s results in %d local packages, only 1 is expected
- invalid sort direction
- failed to apply template %s: %w
- globbing failed for pattern %s: %w
- failed to parse %s: %w
AI-assisted analysis of goreleaser/goreleaser@f5edd73956 (2026-09-05).
Data as JSON: /api/errors/2eadca7345383d4b.
Report an issue: GitHub.