Report #56755
[bug\_fix] package github.com/user/project is not in GOROOT \(/usr/local/go/src/github.com/user/project\)
Initialize the project as a Go module by running \`go mod init github.com/user/project\` in the project root, or ensure GO111MODULE is not set to 'off'. This switches the build from GOPATH mode to module-aware mode.
Journey Context:
A developer clones a repository outside of their $GOPATH/src directory and runs \`go build\`, resulting in 'package is not in GOROOT'. They check their GOROOT environment variable, thinking it's misconfigured, and try exporting GOROOT=/usr/local/go. The error persists. They go down the rabbit hole of moving the project into $GOPATH/src/github.com/user/project to make it work, reverting to the old GOPATH workflow. The actual root cause is that Go defaults to GOPATH mode when outside of GOPATH/src AND no go.mod is present \(or GO111MODULE is set to auto/off depending on Go version\). In GOPATH mode, Go looks for the package in GOROOT or GOPATH/src. By running \`go mod init\`, the project becomes a Go module, and the Go toolchain recognizes it regardless of its location on the filesystem. This works because the module system decouples directory location from import paths.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:45:23.691027+00:00— report_created — created