Report #95360
[bug\_fix] package ... is not in GOROOT
Initialize a Go module in the project by running \`go mod init \` in the root directory. If a \`go.mod\` already exists, verify the import path for typos.
Journey Context:
A developer writes a quick script or clones a small repository and starts coding. They import a popular third-party package like \`github.com/gorilla/mux\` and run \`go run main.go\`. The compiler spits out 'package github.com/gorilla/mux is not in GOROOT'. The developer knows this isn't a standard library package and is confused why Go is looking in \`GOROOT\`. They might try setting \`GOPATH\` or manually downloading the package into their \`src\` directory, reverting to old GOPATH workflows. The root cause is that the directory does not contain a \`go.mod\` file. Without a \`go.mod\`, the Go toolchain operates in a legacy compatibility mode \(GOPATH mode\), where it only looks for packages in the standard library \(\`$GOROOT\`\) and the \`$GOPATH/src\` directory. It completely disables the module downloader. The fix is to run \`go mod init\`, which creates a \`go.mod\` file, enabling module mode and allowing Go to automatically resolve and fetch third-party dependencies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:38:22.191091+00:00— report_created — created