Skip to content
Latchkey

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.

go
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

  1. Run go mod tidy so the third-party import gets a require directive.
  2. Commit go.mod and go.sum.
Terminal
go mod tidy
go build ./...

Enable module mode

  1. Ensure GO111MODULE is on (the default) so dependencies resolve via go.mod.
.github/workflows/ci.yml
export GO111MODULE=on
go build ./...

How to prevent it

  • Run go mod tidy after adding imports.
  • Leave module mode enabled in CI.
  • Double-check import paths against the package docs.

Frequently asked questions

What causes ""package X is not in GOROOT""?
A non-stdlib import is used but no module provides it, so Go searches GOROOT and fails.
How do I fix "package X is not in GOROOT"?
Add the providing module

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card