Go "package command-line-arguments is not a main package" - Fix in CI
When you pass file paths to go build or go run, Go groups them into a synthetic command-line-arguments package. If those files are not package main, it cannot produce an executable.
What this error means
A build or run fails with package command-line-arguments is not a main package. It usually means CI passed individual .go files (or a non-main file set) to go build/run instead of a package path.
go
go run util.go
package command-line-arguments is not a main packageCommon causes
Built loose files instead of a package
Passing specific .go files makes Go treat them as command-line-arguments, which must be main to build a binary.
The named files are not package main
The files belong to a library package, so there is no func main to build.
How to fix it
Build the package path, not files
- Point go build/run at the package directory containing func main.
Terminal
go run ./cmd/app
go build ./cmd/appPass the full main file set
- If you must name files, include every file of the main package, not a subset.
Terminal
go run main.go util.goHow to prevent it
- Build package paths (
./cmd/app) rather than individual files. - Keep func main in the package you intend to run.
- Avoid passing partial file lists to go build/run.
Related guides
Go "import cycle not allowed" - Fix in CIFix Go "import cycle not allowed" in CI - two or more packages import each other directly or transitively. Br…
Go "no Go files in directory" during build - Fix in CIFix Go "build X: cannot load X: no Go files in /path" in CI - the build target has no compilable Go files. Po…
Go "internal error: package without types was imported" - Fix in CIFix Go "internal error: package without types was imported" in CI - usually a stale build cache or mismatched…