Report #67870
[bug\_fix] package example.com/myproject is not in GOROOT \(/usr/local/go/src/example.com/myproject\)
Initialize the Go module by running go mod init example.com/myproject in the project root.
Journey Context:
A developer creates a new directory for a project, writes a main.go file, and runs go build. Instead of compiling, Go spits out an error claiming the package is not in the GOROOT. The developer is baffled—they never intended to put their project in the Go installation directory. They might try reinstalling Go, fiddling with the GOPATH environment variable, or manually moving their code to $GOPATH/src, which feels antiquated. The root cause is that the directory lacks a go.mod file. Without a go.mod file, the Go toolchain falls back to legacy GOPATH mode or misinterprets the import path as a standard library package, searching for it in the GOROOT. The fix is simply to run go mod init example.com/myproject, which creates the go.mod file, explicitly telling the Go toolchain that this directory is the root of a module and defining its import path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:23:57.510410+00:00— report_created — created