Report #10897
[bug\_fix] go: package PACKAGE is not in GOROOT \(/usr/local/go/src/PACKAGE\)
Initialize the Go module by running \`go mod init \` in the project root, or ensure the \`GO111MODULE\` environment variable is set to \`on\`.
Journey Context:
A developer creates a new directory outside of \`$GOPATH/src\`, writes a \`main.go\` file, and runs \`go build\`. The compiler throws an error stating the package is not in GOROOT. The developer is confused because they are importing standard library packages or just trying to build their own \`main\` package. The root cause is that the Go toolchain is operating in GOPATH mode \(legacy behavior\) rather than module-aware mode. This happens if there is no \`go.mod\` file in the current directory or any parent, and \`GO111MODULE\` is set to \`auto\` \(or \`off\` in older versions\). In GOPATH mode, Go expects source code to reside inside \`$GOPATH/src\` and looks for imports there and in \`$GOROOT\`. The fix is to run \`go mod init \` to create a \`go.mod\` file, which explicitly switches the directory into a Go module, telling the toolchain to use module mode regardless of the \`$GOPATH\` location.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:55:25.155767+00:00— report_created — created