Report #4983
[bug\_fix] package github.com/foo/bar is not in GOROOT \(/usr/local/go/src/github.com/foo/bar\)
Initialize a Go module in the project directory by running \`go mod init \`, or ensure \`GO111MODULE\` is not set to \`off\`.
Journey Context:
A developer starts a new project in a directory outside the traditional \`$GOPATH/src\`, writes some code importing a third-party package, and runs \`go build\`. The compiler complains the package is not in GOROOT. They might try moving their project into \`$GOPATH/src\` or manually downloading the dependency. The root cause is that Go is running in "GOPATH mode" rather than "module-aware mode". This happens if the project lacks a \`go.mod\` file and \`GO111MODULE\` is set to \`auto\` \(default in older Go versions\) or \`off\`. In GOPATH mode, Go only looks for packages in \`$GOROOT\` and \`$GOPATH/src\`. The fix is to run \`go mod init \` in the project root. This creates a \`go.mod\` file, which activates module-aware mode, allowing the \`go\` command to resolve and fetch remote dependencies over the internet.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:24:47.629107+00:00— report_created — created