go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision ...?
Asked Answered
C

4

6

My coworker pushed a tag v3.0.1 before updating go.mod to have /v3 suffix (https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher). I have updated module path (go.mod) and all import paths (*.go) to fix it, tagged as v3.0.2.

Now the problem is:

go get -v git.example.com/owner/[email protected]
go: finding git.example.com/owner/repo v3.0.2
go: git.example.com/owner/[email protected]: go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision 
d85c4f69ad17

Found this: go build keeps complaining that: go.mod has post-v0 module path

So, I deleted both v3.0.0 and v3.0.1 tags, pointed it to the latest commit, re-pushed but the problem still stand.

I noticed that go.mod still refered to the old version as an indirect dependency:

require (
    git.example.com/owner.repo v0.1.2 // indirect

Even if I changed it to /v3 v3.0.2 it will be restored to v0.1.12 automatically.

Why?

Did I miss something?


Tue Jul 23 05:54:56 +07 2019

rm go.*
go mod init git.example.com/dependent/project
go mod tidy

and go.mod is updated correctly now:

require (
-       git.example.com/owner/repo v0.1.2
+       git.example.com/owner/repo/v3 v3.0.2

but go get -v git.example.com/owner/[email protected] still returned the error:

go: finding git.example.com/owner/repo v3.0.2
go: git.example.com/owner/[email protected]: go.mod has post-v0 module path "git.example.com/owner/repo/v3" at revision 
d85c4f69ad17

(d85c4f69ad17 is the latest commit in master)

I noticed that there are both v0.1.2 and v3.0.2 in go.sum:

git.example.com/owner/repo v0.1.2 h1:mCGJEmyrFDTCGkRfUIORpqdrNkSONQ6K+AcTNgxqveY=
git.example.com/owner/repo v0.1.2/go.mod h1:FfUKnyPrARCtAXQZ3BQVJI7h2eJ0UpQBMLg4bNs4Kdc=
git.example.com/owner/repo/v3 v3.0.2 h1:mJtDKLeiP8vMRSZo08i/k/KDbIoZTlKW2aWu7DUBvMM=
git.example.com/owner/repo/v3 v3.0.2/go.mod h1:64LE0ts0Lk9InIQyhPYGmnxs6LZIl6H4Iorl1EXfqxo=
Cumuliform answered 22/7, 2019 at 10:14 Comment(0)
C
6

Please pay attention to my go get command:

go get -v git.example.com/owner/[email protected]

It should be:

go get -v git.example.com/owner/repo/[email protected]
Cumuliform answered 23/7, 2019 at 8:7 Comment(1)
Thank you! This finally saved me from a ton of frustration. :DDeclare
E
1

Expanding on the answer from @quanta...

You are doing:

go get -v git.example.com/owner/[email protected]

Because it is a v3 module, the go get command should include a /v3 before the @:

go get -v git.example.com/owner/repo/[email protected]

Once a v3.x.y package is a module with its own go.mod, then whenenver you are operating with modules enabled, you pretty much always include the /v3 whenever you reference the v3.x.y module, including in:

  • arguments to go get on the command line
  • import statements in .go code for the consumer
  • require statements in a consumer's go.mod
  • replace or exclude statements in a consumer's go.mod
  • the module line of the v3 module's go.mod file
  • internal import statements in .go code inside the v3 module importing other packages in the v3 module
  • etc.

One way to think about it is that the module's name is now effectively git.example.com/owner/repo/v3, where its name includes the trailing /v3.

If you are a consumer of a vN module and need to update your import paths in your .go files to include the vN, then github.com/marwan-at-work/mod is a commonly used tool from the community that automates adding the /vN in all the required spots. Separately, it also automates placing the /vN in all the required spots if you are a module author for a v2+ module.

From the "Semantic Import Versioning" section of the Go modules wiki:

If the module is version v2 or higher, the major version of the module must be included as a /vN at the end of the module paths used in go.mod files (e.g., module github.com/my/mod/v2, require github.com/my/mod/v2 v2.0.0) and in the package import path (e.g., import "github.com/my/mod/v2/mypkg").

Ensanguine answered 3/8, 2019 at 23:0 Comment(0)
P
0

for example you can replace repository with this hack: https://github.com/golang/go/wiki/Modules

require {
...
}

replace git.example.com/owner.repo v0.1.2 => git.example.com/owner.repo v3.0.2

or you can use go get at the commit hash you want:

go get git.example.com/owner.repo@af044c0995fe

go get will correctly update the dependency files (go.mod, go.sum).

For more information: https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies

or for last example you should clean cache

  1. remove go.mod and go.sum
  2. go cache clean
  3. go mod vendor
Protectionist answered 22/7, 2019 at 11:17 Comment(4)
2 things: 1. it didn't work (same error as above). 2. Even if it works, it's just a hack. What if I have 100 dependent projects, I have to update all of them when release a new tag?Cumuliform
@Cumuliform I Update answer. Try itProtectionist
@Cumuliform last Examle is: 1. remove go.mod and go.sum 2. go cache clean 3. go mod vendor It helps me in similar situatuonProtectionist
Why go mod vendor? The problem is when I run go get -v [email protected] it happened again.Cumuliform
H
0

I may have had a similiar issue where I updated a module to use the /v2 import path but go getting the module always returned an error about invalid go.mod

The solution was to go get -u github.com/<me>/<pkg>/v2

Hypo answered 23/10, 2019 at 7:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.