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

Created on 21 Nov 2019  路  15Comments  路  Source: golang/go

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/[email protected]

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锛孊ecause 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 ?

Most helpful comment

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

All 15 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.

go get github.com/google/[email protected]: github.com/google/[email protected]: 
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...

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

Okay, thank you very much, master!

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

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 get -v -u github.com/zeromq/goczmq 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 ? )

@bcmills Could you explain again why running go get foo@v7 fails? The reason you gave earlier was technical, but I don't understand why this policy exists. It would be helpful if you could shine some more light on this.

I would expect that go get github.com/foo/foo@v7 would look for a v7 tag or a github.com/foo/foo/v7 path, write the resolved path into my go.mod and download it. That seems reasonable, and it's how other similar tools work (e.g. npm).

A concrete example. I am trying to download github.com/golang-migrate/migrate. They just released version 4.10. Here is the GitHub release link.

Getting the specific version fails.

$ go get -u github.com/golang-migrate/[email protected]
go: finding github.com/golang-migrate/migrate v4.10.0
go: finding github.com/golang-migrate/migrate v4.10.0
go get github.com/golang-migrate/[email protected]: github.com/golang-migrate/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v4

Getting the major version fails

See go.mod.

$ go get -u github.com/golang-migrate/migrate@v4
go get github.com/golang-migrate/migrate@v4: no matching versions for query "v4"

Getting without a version gets the wrong version

$ go get -u github.com/golang-migrate/migrate
$ go clean -i -n github.com/golang-migrate/migrate
cd /Users/dzrtc/go/pkg/mod/github.com/golang-migrate/[email protected]+incompatible

Workaround from the golang-migrate issue tracker

Lots of people are having the same problem. Someone figured out this workaround.

$ go get -tags 'postgres' -u github.com/golang-migrate/migrate/v4/cmd/migrate/
go: finding github.com/golang-migrate/migrate/v4 v4.10.0
go: downloading github.com/golang-migrate/migrate/v4 v4.10.0
go: extracting github.com/golang-migrate/migrate/v4 v4.10.0

Questions

  1. What is the recommended solution for getting v4.10.0 of this package?
  2. Is the @v99 notation still under development? Should we expect it to do anything?
  3. What does incompatible mean in this context?
  4. What does go get -tags do? It appears to be undocumented (go help get | grep "tags" returns nothing)
  5. Is there a way to ask go get to list or report all of the @versions that it sees for a particular target? Is it theoretically possible to write such a feature?

Thanks for helping.

+1

Also hitting this in go-sqlite3: https://github.com/mattn/go-sqlite3/issues/812

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/[email protected] 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
      ...
)

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.

The problem with the error is that it doesn't point the user toward the solution: add major version to import path. This is by no means a good error message, but it contains actionable information.

invalid module path: v2.2.1 expects github.com/zouyx/agollo/v2

@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)!

@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/[email protected]
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)

Was this page helpful?
0 / 5 - 0 ratings