Report #23172
[bug\_fix] package github.com/foo/bar is not in GOROOT \(/usr/local/go/src/github.com/foo/bar\)
Ensure the module is initialized \(go mod init\) and the import path matches the module path, or run go mod tidy to fetch the dependency. Do not build in GOPATH mode if using modules.
Journey Context:
A developer creates a fresh directory for a new CLI tool, writes a main.go that imports github.com/spf13/cobra, and runs go build. The compiler spits out package github.com/spf13/cobra is not in GOROOT \(/usr/local/go/src/github.com/spf13/cobra\). They check their internet connection, try go install, and wonder why Go is looking for a third-party package in the standard library directory. The rabbit hole leads them to realize they skipped the initialization step. Without a go.mod file in the current directory, the Go toolchain \(especially in Go 1.16\+\) gets confused and falls back to looking for the package in the GOROOT or GOPATH/src. It doesn't know how to fetch remote modules. The fix works because go mod init creates a go.mod file, which explicitly tells the Go toolchain to operate in module mode, enabling it to resolve remote dependencies via the network and the module cache rather than searching local standard library paths.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T17:18:14.990887+00:00— report_created — created