Go "package X is not in std" - Fix Bad Stdlib Imports in CI
Go looked up an import as a standard-library package and there is no such package in std. The import path is misspelled, refers to a removed/relocated stdlib package, or should have been a third-party module.
What this error means
A build fails with package <path> is not in std (<GOROOT>/src/<path>). The path looks like a standard-library import but does not exist in the toolchain’s standard library.
main.go:5:2: package math/random is not in std
(/usr/local/go/src/math/random)Common causes
A misspelled standard-library path
A typo (math/random instead of math/rand, encoding/jsonn) names a package that does not exist in std.
A package that moved or was removed
An old import (e.g. io/ioutil helpers relocated, or an experimental path) no longer resolves in the standard library of the current Go version.
A third-party path mistaken for stdlib
An import that looks standard but is actually a module (and is missing from go.mod) is reported as not in std.
How to fix it
Correct the import path
Fix the spelling to the real standard-library package, or migrate to its replacement.
# example corrections
# math/random -> math/rand
# io/ioutil.ReadAll -> io.ReadAll (Go 1.16+)
goimports -w .
go build ./...Add the module for a non-stdlib import
If the package is third-party, require it so it resolves as a module rather than std.
go get github.com/org/realpkg
go mod tidyHow to prevent it
- Let
goimportsmanage and verify import paths. - Check the standard library docs for the exact package name.
- Run
go build ./...before merging to catch bad imports early.