Report #7681
[bug\_fix] package example.com/myproject/mypackage is not in GOROOT \(/usr/local/go/src/example.com/...\)
Ensure GO111MODULE is set to 'on' \(or auto\) and that a valid go.mod file exists in the project root by running \`go mod init example.com/myproject\`.
Journey Context:
A developer clones a newer Go project or creates a new directory outside their GOPATH. Upon running \`go build\`, Go throws an error claiming the package is not in GOROOT. They waste time checking their GOPATH environment variable, creating nested src directories, and symlinking folders, trying to force the old GOPATH resolution. The root cause is that without a go.mod file, and depending on the Go version or GO111MODULE setting, the Go toolchain falls back to GOPATH mode. In GOPATH mode, it looks for packages in $GOPATH/src or $GOROOT/src, not the current directory. Initializing the module with \`go mod init\` works because it creates a go.mod file, forcing the Go toolchain into module mode, where the project root is self-contained and imports are resolved via the module cache rather than global system paths.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:22:58.328189+00:00— report_created — created