Skip to content
Latchkey

Go "# command-line-arguments" Build Errors - Fix in CI

When you pass individual .go files to go build instead of a package path, Go compiles them as a synthetic package it labels command-line-arguments. Any error then appears under that header, and the build breaks if the listed files are not a complete package.

What this error means

Output shows # command-line-arguments followed by undefined symbols, or named files must all be in one directory. It happens when CI runs go build main.go or go run file.go instead of go build ./....

go build output
# command-line-arguments
./main.go:12:6: undefined: helperFunc
# or
named files must all be in one directory; have ./cmd/ and ./internal/

Common causes

Building a single file instead of the package

Passing main.go alone omits the package’s other files, so symbols defined elsewhere in the package are undefined under the command-line-arguments pseudo-package.

Listing files from multiple directories

Go can only treat files from one directory as a package on the command line; mixing directories triggers named files must all be in one directory.

How to fix it

Build packages, not files

Target package import paths so Go includes every file in the package.

Terminal
go build ./...
# or a specific package
go build ./cmd/server

Run a package with go run

Use the package path so all its files are compiled together.

Terminal
go run ./cmd/server   # not: go run cmd/server/main.go

How to prevent it

  • Use package paths (./..., ./cmd/x) in CI, never bare file names.
  • Reserve file-list builds for single-file scripts only.
  • Standardize build commands across the pipeline.

Related guides

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