Report #52372
[bug\_fix] import is a program, not an importable package
Move the \`main\` function and its associated \`package main\` declaration into a directory named \`cmd/\` or \`main\`, and import the library code from the root module. The root cause is that the developer is trying to import a package that is declared as \`package main\`, which Go forbids because \`main\` packages define executable programs, not importable libraries.
Journey Context:
A developer builds a monorepo-style Go module. They put their executable code \(with \`func main\(\)\` and \`package main\`\) in the project root directory alongside their library code. Later, they try to import some shared logic from the root module into another sub-package using the module's own path. The build fails with 'is a program, not an importable package'. The developer tries changing the package name in the import, checking for circular dependencies, and fiddling with \`replace\` directives. The realization hits when they understand Go's strict package rules: a \`package main\` cannot be imported. The established pattern is to keep the root module as a library \(or empty\) and place executables under a \`cmd/\` directory \(e.g., \`cmd/myapp/main.go\`\). Refactoring the code into this structure allows the library code to be imported cleanly while the \`main\` package remains isolated.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:24:05.542269+00:00— report_created — created