golang/go · error
no such package: %s
Error message
no such package: %s
What it means
Returned by the `go doc` argument loop when parseArgs returns a nil buildPackage for the requested path. The package could not be located/resolved at all, so there is nothing to document. Triggered after the loop's first iteration regardless of the 'more' bit, since a nil package with no further candidates is a dead end.
Source
Thrown at src/cmd/go/internal/doc/doc.go:255
return doPkgsite(ctx, "std", "")
}
// If args are provided, we need to figure out which page to open on the pkgsite
// instance. Run the logic below to determine a match for a symbol, method,
// or field, but don't actually print the documentation to the output.
writer = io.Discard
}
var paths []string
var symbol, method string
// Loop until something is printed.
dirs.Reset()
for i := 0; ; i++ {
buildPackage, userPath, sym, more := parseArgs(ctx, flagSet, flagSet.Args())
if i > 0 && !more { // Ignore the "more" bit on the first iteration.
return failMessage(paths, symbol, method)
}
if buildPackage == nil {
return fmt.Errorf("no such package: %s", userPath)
}
// The builtin package needs special treatment: its symbols are lower
// case but we want to see them, always.
if buildPackage.ImportPath == "builtin" {
unexported = true
}
symbol, method = parseSymbol(flagSet, sym)
pkg := parsePackage(writer, buildPackage, userPath)
paths = append(paths, pkg.prettyPath())
defer func() {
pkg.flush()
e := recover()
if e == nil {
return
}View on GitHub (pinned to b6b368adc5)
Solutions
- Verify the package path with `go list ./...` or `go list -m all`.
- Run `go mod tidy` to ensure dependencies are present.
- Check build tags/GOOS/GOARCH if the package is platform-specific.
- Correct typos in the import path.
Example fix
# before $ go doc exampl.com/foobar # typo # -> no such package: exampl.com/foobar # after $ go doc example.com/foobar
Defensive patterns
Strategy: validation
Validate before calling
// confirm the package resolves before invoking doc
if out, err := exec.Command("go", "list", userPath).CombinedOutput(); err != nil {
return fmt.Errorf("package does not resolve: %s", out)
} Try / catch
if err != nil && strings.Contains(err.Error(), "no such package") {
// suggest `go list ./...` matches and retry
} Prevention
- Run `go list ./...` to discover valid paths first.
- Keep `go mod tidy` current so paths resolve.
- Watch build tags for platform-specific packages.
When it happens
Trigger: Running `go doc <path>` where <path> does not resolve to any importable package — typo, nonexistent module path, package behind a build constraint that excludes the current tags, or a path that only matches directories but not a package.
Common situations: Typo'd import path; package behind GOOS/GOARCH or build tags not active; missing dependency (`go mod tidy` needed); pointing at a directory with no .go files.
Related errors
- no symbol %s in package%s
- pattern %q does not specify a single package
- cannot combine -all and -short
- no method or field %s.%s in package%s
- path %q matched multiple packages
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/fa8d9458dcc7e2e2.
Report an issue: GitHub.