Skip to content
Latchkey

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 abcdef

Common 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

  1. List available versions and pick a full vX.Y.Z tag.
  2. 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 tidy

Use a correct pseudo-version

  1. 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 get generate pseudo-versions rather than hand-writing them.
  • Verify tags exist upstream before requiring them.

Related guides

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