Go "package X is not in GOROOT" - Fix in CI
Go looked for an import in the standard library at GOROOT and did not find it. The path is misspelled, third-party, or the project is not running in module mode.
What this error means
A build fails with package X is not in std (GOROOT/src/X). It usually means a third-party import was written as if it were stdlib, or modules are disabled so Go fell back to GOROOT/GOPATH lookup.
main.go:4:2: package github.com/foo/bar is not in std (/usr/local/go/src/github.com/foo/bar)Common causes
Third-party import not required
A non-stdlib import is used but no module provides it, so Go searches GOROOT and fails.
Modules disabled
With GO111MODULE=off Go resolves against GOROOT/GOPATH only, so module dependencies look like missing stdlib.
How to fix it
Add the providing module
- Run go mod tidy so the third-party import gets a require directive.
- Commit go.mod and go.sum.
go mod tidy
go build ./...Enable module mode
- Ensure GO111MODULE is on (the default) so dependencies resolve via go.mod.
export GO111MODULE=on
go build ./...How to prevent it
- Run
go mod tidyafter adding imports. - Leave module mode enabled in CI.
- Double-check import paths against the package docs.