Skip to content
Latchkey

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.

go build output
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.

Terminal
# 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.

Terminal
go get github.com/org/realpkg
go mod tidy

How to prevent it

  • Let goimports manage and verify import paths.
  • Check the standard library docs for the exact package name.
  • Run go build ./... before merging to catch bad imports early.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →