Report #24963
[bug\_fix] package mypackage is not in GOROOT \(/usr/local/go/src/mypackage\)
Initialize the Go module by running \`go mod init \` in the project root directory.
Journey Context:
A developer clones a repository or starts a new project and creates a main.go file. When they run \`go run main.go\` or \`go build\`, they get an error saying their local package is not in GOROOT. They check their GOPATH and Go installation, which are perfectly fine. The issue is that there is no go.mod file in the directory or any parent directory. Without a go.mod, the Go toolchain falls back to the legacy GOPATH mode. In GOPATH mode, imports are resolved relative to $GOPATH/src or $GOROOT/src, so the compiler looks for the local package inside the Go installation directory \(GOROOT\) and fails. Creating a go.mod file explicitly defines the module root, switching the compiler to module-aware mode where local imports are resolved relative to the go.mod location.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:18:36.021783+00:00— report_created — created