Report #15590
[bug\_fix] go: found packages mypkg and mypkg\_utils in /path/to/dir
Ensure all .go files in a single directory declare the exact same package name \(except \_test.go files which can declare package mypkg\_test\). Move files with a different package declaration into their own subdirectory.
Journey Context:
A developer adds a new utility file utils.go to their project's root directory, declaring it as package utils, while main.go is package main. When they run go build, the compiler complains about finding multiple packages in the same directory. Coming from languages like Java or Python where a folder can contain multiple namespaces, they are confused. They check for syntax errors or hidden characters, but the issue is fundamental to Go's design: Go maps packages to directories strictly on a 1:1 basis. A directory can only belong to one package. They resolve it by either changing utils.go to package main, or moving it to a utils/ subdirectory and importing it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:27:21.592263+00:00— report_created — created