Go "go generate: no such tool" - Fix in CI
A //go:generate line shells out to whatever command it names. When that command is not installed or not on PATH in the runner, generate aborts before producing any output.
What this error means
Running go generate ./... in CI fails with no such tool or executable file not found in $PATH. Locally the generator was installed; the runner has a clean PATH and never received it.
go
app/models.go:3: running "stringer": exec: "stringer": executable file not found in $PATH
go generate: no such tool "stringer"Common causes
Generator never installed in CI
The tool was on your local machine but the workflow never ran go install for it, so the runner PATH has nothing to exec.
GOBIN not on PATH
go install placed the binary in GOBIN/GOPATH/bin, but that directory was not added to PATH, so the directive cannot find it.
How to fix it
Install the generator before generate
- Add a step that go installs each tool the directives invoke.
- Run go generate after the install so the binaries exist on PATH.
.github/workflows/ci.yml
- run: go install golang.org/x/tools/cmd/stringer@latest
- run: go generate ./...Pin tools in a tools.go file
- Track generators as build constraints so versions are pinned in go.mod.
- Install them from the module before generating.
tools.go
//go:build tools
package tools
import _ "golang.org/x/tools/cmd/stringer"How to prevent it
- Pin generators in a tools.go build-tagged file so versions never drift.
- Install every generator in CI before running go generate.
- Add GOBIN (or $(go env GOPATH)/bin) to PATH in the workflow.
Related guides
Go "protoc-gen-go: program not found" - Fix in CIFix protoc "protoc-gen-go: program not found or is not executable" in CI - the Go protobuf plugin is not inst…
Go buf "breaking change detected" - Fix in CIFix buf "breaking" failures in CI - a proto change broke wire or API compatibility against the baseline. Make…
Go cgo "undefined reference" (C link) - Fix in CIFix Go cgo "undefined reference to" link errors in CI - the linker could not find a C symbol because the libr…