go: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

What version of Go are you using (go version)?

$ go version
go version go1.13.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/go"
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/xxx/workspace/test/apollo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kc/jryd_rpn6_l03ykk8q84d6740000gp/T/go-build000733542=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go get github.com/zouyx/agollo@v2.2.1

What did you expect to see?

Correctly download this module.

What did you see instead?

invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

I import the thirdparty module. The module has the latest version v2.2.1. A project is developing , but go forbid me to get the latest version to continue develop my project,Because the module not compatible with sematic import versioning. Through, I found a way to solve this issue

go get github.com/zouyx/agollo@master

but on go.mod, the version be taged with v1.9.1-0.20191114083447-dde9fc9f35b8 , it is ambiguous . the module not contain version v1.9.1. How i to solve this ?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

The error message is correct. See https://golang.org/cmd/go/#hdr-Module_compatibility_and_semantic_versioning.

The v1.9.1-0.[…] version string is a pseudo-version generated from the requested commit.

From the perspective of the go command, this is working as designed.

yikes, this is not great UX, I hope the Go authors will reconsider some of these choices, or at least improve the error message

Issue should be opened until the error message is made more clear. Users shouldn’t have to Google an error message to find out what it means. Take some notes from Rust and cargo.

@icholy and @m-cat, this issue is closed, and the issue as originally reported was a failure to download the module, not the wording of the resulting error message.

That said, we do want to make the errors as clear as possible. If you have a specific improvement to suggest in the phrasing of the error, please open a new issue (or send a change with the proposed improvement)!

@wrfly, use the import path declared in the go.mod file: github.com/google/go-github/v29, not github.com/google/go-github.

So I’ve been just bitten by this:

require (
	github.com/zeromq/goczmq v4.2.0
)

While: https://github.com/zeromq/goczmq/blob/master/go.mod has

module github.com/zeromq/goczmq/v4

But I still get:

go get -v -u github.com/zeromq/goczmq/v4
go: errors parsing go.mod:
go.mod:9: require github.com/zeromq/goczmq: version "v4.2.0" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v4

While:

go: github.com/zeromq/goczmq upgrade => v4.1.0+incompatible

gives me v4.1.0 which is an older release (and marks it as incompatible ? )

Sorry to be snarky, but cmake solved this long long ago

I wanna use the latest version of github.com/tealeg/xlsx in my project. go get -u github.com/tealeg/xlsx doesn’t work and go get github.com/tealeg/xlsx@3.0.0 occurs an error as follows:

require github.com/tealeg/xlsx: version “v3.0.0” invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3

Here is my solution:

import "github.com/tealeg/xlsx/v3"

then go mod tidy. Eventually, go.mod requires the latest version:

require (
      ...
      github.com/tealeg/xlsx v1.0.5
      github.com/tealeg/xlsx/v3 v3.0.0
      ...
)

@bcmills Can you investigate more? I can still report errors docker run -it golang:sha256:cbd5e567cfb8a2119d231039809fbdbcc0d2dc9436d150da422a52ad550fb9b2

go get -u github.com/boyter/scc/v2 - returns weird “can only find 2.12.0+incompatible” I cannot in any way write a go get command that downloads boyter/scc@v2.13.0 go get -u github.com/boyter/scc@v2 downloads v2.12.0+incompatible (after go mod init <anything>)

the workaraound for me was git clone --branch v2.13.0 --depth 1 https://github.com/boyter/scc then go build but it doesn’t really seem to work properly (but that is probably on my part)

So I would argue that the error is there! There IS a failure to download the module (at the given version)

go get github.com/google/go-github@v29.0.2: github.com/google/go-github@v29.0.2: 
invalid version: module contains a go.mod file, so major version must be compatible:
should be v0 or v1, not v29

Hi masters, how to solve this? it’s under google…