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 ./....
# 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.
go build ./...
# or a specific package
go build ./cmd/serverRun a package with go run
Use the package path so all its files are compiled together.
go run ./cmd/server # not: go run cmd/server/main.goHow 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.