Go "invalid version" fetching module - Fix in CI
Go resolves module versions to a tag or a pseudo-version. A malformed or non-existent version string cannot be resolved, so the fetch fails.
What this error means
A go get or build fails with invalid version: unknown revision or invalid version: should be vX.Y.Z. It means the version requested in go.mod or on the command line does not exist or is malformed.
go
go: github.com/foo/bar@v1.2: invalid version:
should be v1.2.0 or a valid semver tag
go: github.com/foo/bar@latest: invalid version: unknown revision abcdefCommon causes
Truncated or non-semver version
A version like v1.2 (no patch) or a non-semver string is not a valid module version.
Revision does not exist
A commit hash or tag was requested that the upstream repository does not contain.
How to fix it
Request a valid semver version
- List available versions and pick a full vX.Y.Z tag.
- Run go get with the correct version and tidy.
Terminal
go list -m -versions github.com/foo/bar
go get github.com/foo/bar@v1.2.0
go mod tidyUse a correct pseudo-version
- For an untagged commit, use the full pseudo-version generated by go get.
Terminal
go get github.com/foo/bar@<full-commit-sha>How to prevent it
- Always pin full vX.Y.Z versions, not truncated tags.
- Let
go getgenerate pseudo-versions rather than hand-writing them. - Verify tags exist upstream before requiring them.
Related guides
Go "410 Gone" fetching module from proxy - Fix in CIFix Go "410 Gone" fetching a module from the proxy in CI - a missing version or a transient proxy hiccup. Pin…
Go "module declares its path as X but required as Y" - Fix in CIFix Go "module declares its path as X but was required as Y" in CI - the imported module path disagrees with…
Go "cannot find module providing package" - Fix in CIFix Go "cannot find module providing package X" in CI - an imported package is not required by go.mod. Add th…