Report #46817
[bug\_fix] package myapp is not in GOROOT
Run \`go mod init \` in the project root to enable module mode.
Journey Context:
A developer creates a new folder, writes main.go with \`package main\`, and runs \`go run main.go\`. It fails. They think their Go installation is corrupted because it's looking in GOROOT. They reinstall Go, but the error persists. The rabbit hole: They try setting GOPATH to their project directory, which doesn't help. The realization: If there is no go.mod file in the current directory or any parent, the go command runs in GOPATH mode \(or legacy mode\). In this mode, it expects all imports to be inside $GOPATH/src or $GOROOT. Since myapp is neither, it fails. The fix works because \`go mod init\` creates a go.mod file, turning on module mode. Module mode allows the Go toolchain to recognize the current directory as the root of the myapp module, resolving the import correctly without relying on the legacy GOPATH directory structure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:03:18.812246+00:00— report_created — created