Skip to content
Latchkey

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 package

Common 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

  1. Point go build/run at the package directory containing func main.
Terminal
go run ./cmd/app
go build ./cmd/app

Pass the full main file set

  1. If you must name files, include every file of the main package, not a subset.
Terminal
go run main.go util.go

How 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →