Go modules v2.0.0 won't work (but v2.0.1 will)

1,056 views
Skip to first unread message

Francesc Campoy Flores

unread,
Jun 14, 2019, 7:24:34 PM6/14/19
to golang-nuts

Hi everyone,


I have a pretty weird error with Go modules that I can't explain - after some investigation I feel this might be a bug but I'd like to have some extra eyes on it.


I have migrated my tools repository (github.com/campoy/tools) to use Go modules and as a test I've tagged two major version v1.0.0 and v2.0.0.


I then wrote a little program the flags package in the tools modules that looks like this:


package main

import (
    "flag"
    "fmt"
    "image/color"

    "github.com/campoy/tools/flags"
)

func main() {
    h := flags.HexColor("color", color.Black, "color")
    flag.Parse()

    fmt.Println(h.RGBA())
}


which produced the following go.mod:


module github.com/campoy/tests/mods

go 1.12

require github.com/campoy/tools v1.0.0


Now, when I try to use v2.0.0 I modify the import path of the program to use github.com/campoy/tools/v2/flags and the require line to be require github.com/campoy/tools/v2 v2.0.0


When I try to build this the compilation fails with the error message:


go: github.com/campoy/tools/v...@v2.0.0: go.mod has non-.../v2 module path "github.com/campoy/tools" (and .../v2/go.mod does not exist) at revision v2.0.0
go: error loading module requirements


But if I instead use the tag v2.0.1 which points to the same commit as v2.0.0 everything works correctly.


Am I doing something wrong or does this seem like a real bug?

Francesc Campoy Flores

unread,
Jun 14, 2019, 7:30:48 PM6/14/19
to golang-nuts
Turns out my code was correct and the only problem was that somehow the cache was corrupted.

I ran go clean -modcache and everything is now working.


On Friday, June 14, 2019 at 4:24:34 PM UTC-7, Francesc Campoy Flores wrote:

Hi everyone,


I have a pretty weird error with Go modules that I can't explain - after some investigation I feel this might be a bug but I'd like to have some extra eyes on it.


I have migrated my tools repository (github.com/campoy/tools) to use Go modules and as a test I've tagged two major version v1.0.0 and v2.0.0.


I then wrote a little program the flags package in the tools modules that looks like this:


package main

import (
    "flag"
    "fmt"
    "image/color"

    "github.com/campoy/tools/flags"
)

func main() {
    h := flags.HexColor("color", color.Black, "color")
    flag.Parse()

    fmt.Println(h.RGBA())
}


which produced the following go.mod:


module github.com/campoy/tests/mods

go 1.12

require github.com/campoy/tools v1.0.0


Now, when I try to use v2.0.0 I modify the import path of the program to use github.com/campoy/tools/v2/flags and the require line to be require github.com/campoy/tools/v2 v2.0.0


When I try to build this the compilation fails with the error message:


go: github.com/campoy/tools/v2@v2.0.0: go.mod has non-.../v2 module path "github.com/campoy/tools" (and .../v2/go.mod does not exist) at revision v2.0.0
go: error loading module requirements
Reply all
Reply to author
Forward
0 new messages