Go "invalid go version" in go.mod - Fix the go Directive in CI
The go and toolchain directives in go.mod must follow a strict version format. A hand-edited or malformed value - wrong precision, a stray prefix, or an impossible version - makes the toolchain reject the file outright.
What this error means
A go command fails parsing go.mod with invalid go version "..." or go directive ... must match format 1.23. Nothing builds because Go cannot even read the module file.
go: errors parsing go.mod:
/app/go.mod:3: invalid go version '1.21.0.1': must match format 1.23Common causes
A malformed go directive
The go line was hand-edited to a value Go does not accept - too many components, a v prefix, or a non-existent version - so parsing fails.
A toolchain directive Go cannot use
A toolchain go1.X line with a bad format or a version the runner cannot obtain stops the command before the build.
How to fix it
Set a valid go directive
Use go mod edit so the directive is written in the exact format the toolchain expects.
go mod edit -go=1.23
go mod tidyFix or drop the toolchain line
Set a valid toolchain value, or remove it to let GOTOOLCHAIN handling decide.
go mod edit -toolchain=go1.23.2
# or remove it entirely
go mod edit -toolchain=noneHow to prevent it
- Edit
go/toolchaindirectives withgo mod edit, not by hand. - Keep the directive in the format Go expects (e.g.
1.23or1.23.2). - Commit a tidy go.mod and verify it parses with
go mod verify.