go build keeps complaining that: go.mod has post-v0 module path
Asked Answered
R

2

17

Following the release of Go 1.11, I have been trying to move my repositories to Go modules, by adding a go.mod file at their root.

One of my root libraries my.host/root is in its version 17.0.1, so I wrote in its go.mod file:

module my.host/root/v17

I tagged that version v17.0.1 as documented in the Go modules manual.

When I try to make a new Go project that uses my root library, like:

package main

import root "my.host/root/v17"

func main() {
    root.DoSomething()
}

And try to compile it, I get the following error:

go: my.host/[email protected]: go.mod has post-v0 module path "my.host/root/v17" at revision 6bc78016491a

I am at loss figuring out why this happens. I explicitly added v17.0.1 in the go.mod file, yet every attempt at go build replaces the entry with a v0.0.0-20180828034419-6bc78016491a version which then fails because at that commit, the go.mod file module entry of my root library indeed ends with a v17, as it should.

For the record, this commit is the same as the tagged v17.0.1 version.

What am I doing wrong here? How can I debug this situation?

Rosy answered 28/8, 2018 at 4:34 Comment(4)
A don't think the module name should contain the v17 (only the import statements do),Hexa
@Hexa I am not sure about this: The go modules documentation says: "Update the go.mod file to include a /v2 at the end of the module path. Tag the release with v2.0.0."Rosy
You are right, seems I was wrong.Hexa
That error message is complaining about an import statement or require (or similar) missing the /v17 from the module name. See this answer for a longer explanation, including more about where the /vN is required for a v2+ module, as well as a pointer to a community tool that knows how to automatically update everything that needs to be updated if you are a consumer or author of a v2+ module.Upsilon
R
16

I had make two mistakes:

  • My initial v17.0.0 tag would point to a commit where go.mod did not contain the v17 import path suffix. As a result, it seems Go tooling considers the whole v17 major version as a v0/v1 instead, even if later v17 tags point to a commit with a correct go.mod directive, hence the commit ID "translation".
  • In my dependent projects, in the go.mod file, I mistakenly specified
    require my.host/root v17.0.1 instead of
    require my.host/root/v17 v17.0.1.

After fixing both those issues, everything seems back to normal and it works perfectly. I wish the documentation had been clearer about this but I guess this is a good opportunity to make a contribution!

Rosy answered 28/8, 2018 at 12:48 Comment(1)
To add to the above answer, this section in the Go repo wiki hints at the solution too.Profant
A
14

The error I got was: github.com/emicklei/[email protected]: go.mod has post-v0 module path "github.com/emicklei/go-restful/v2" at revision 3658237ded10

Appending github.com/emicklei/go-restful with v2 like so: github.com/emicklei/go-restful/v2 in my go.mod file fixed it for me.

Astrogate answered 20/2, 2019 at 11:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.