go-colorable icon indicating copy to clipboard operation
go-colorable copied to clipboard

Go modules bug

Open solher opened this issue 6 years ago • 13 comments

When trying to go get go-colorable from gopkg, I'm currently getting this message (using Go 1.12):

go get -u gopkg.in/mattn/go-colorable.v0
go: gopkg.in/mattn/[email protected]: go.mod has non-....v0 module path "github.com/mattn/go-colorable" at revision v0.1.1
go get: error loading module requirements

It seems to me like there is some kind of conflict between the gopkg.in/mattn/go-colorable.v0 actual package path and the name of the module declared in the go.mod file github.com/mattn/go-colorable.

For now, forcing the use of the lib without the go.mod file in it solves the issue:

go get -u gopkg.in/mattn/[email protected]
go: finding gopkg.in/mattn/go-colorable.v0 v0.1.0
go: downloading gopkg.in/mattn/go-colorable.v0 v0.1.0
go: extracting gopkg.in/mattn/go-colorable.v0 v0.1.0

solher avatar Mar 05 '19 16:03 solher

FWIW, I've hit this too. For me it's an indirect dep (i.e. the line go is complaining about in go.mod doesn't exist at all; it just exists in go.sum), and it seems your trick doesn't work:

go get -u gopkg.in/mattn/[email protected]
go: gopkg.in/mattn/[email protected]: go.mod has non-....v0 module path "github.com/mattn/go-colorable" at revision v0.1.1
go get: error loading module requirements

tych0 avatar Mar 06 '19 17:03 tych0

I filed https://github.com/golang/go/issues/30636, let's see what they say.

tych0 avatar Mar 06 '19 17:03 tych0

same thing with gopkg.in/mattn/go-isatty.v0 not a coincidence...

jeanlucmongrain avatar Mar 13 '19 02:03 jeanlucmongrain

FWIW the go bugs suggest it's an issue in the go.mod file or versions here, and that you can use a version that predates this issue. Adding an override to go.mod helped.

replace gopkg.in/mattn/go-colorable.v0 => github.com/mattn/go-colorable v0.1.0

replace gopkg.in/mattn/go-isatty.v0 => github.com/mattn/go-isatty v0.0.6

directionless avatar Mar 21 '19 01:03 directionless

Looks like the problem is in the go.mod file that has the wrong import path: https://github.com/mattn/go-colorable/blob/8029fb3788e5a4a9c00e415f586a6d033f5d38b3/go.mod#L1

it should be:

 module gopkg.in/mattn/go-colorable.v0 

the same import should be fixed on go-isatty too I think.

cmaglie avatar May 30 '19 10:05 cmaglie

I don't use gopkg. So this is not a bug.

mattn avatar May 30 '19 11:05 mattn

The problem is with go mod not gopkg.

Here the steps to reproduce:

~/Workspace/test$ go mod init test
go: creating new go.mod: module test

~/Workspace/test$ cat > main.go
package main

import "gopkg.in/mattn/go-colorable.v0"

func main() {
}

~/Workspace/test$ go build
go: downloading gopkg.in/mattn/go-colorable.v0 v0.1.2
build test: cannot load gopkg.in/mattn/go-colorable.v0: cannot find module providing package gopkg.in/mattn/go-colorable.v0

cmaglie avatar May 30 '19 11:05 cmaglie

ah, now I see what you mean, I must import:

import "github.com/mattn/go-colorable"

instead of:

import "gopkg.in/mattn/go-colorable.v0"

that solved the issue for me. Thanks!

cmaglie avatar May 30 '19 14:05 cmaglie

Having the same issue using with go and vgo.

$ go fmt go: downloading gopkg.in/mattn/go-colorable.v0 v0.1.2 go: downloading gopkg.in/mattn/go-isatty.v0 v0.0.8 build consultent/noodle-node: cannot find module for path gopkg.in/mattn/go-colorable.v0

I'm not sure why it's trying to get it from gopkg.in. I have require "github.com/mattn/go-colorable" in both the go file, and go.mod

I'd rather not move my code under $GOPATH/src

EDIT/UPDATE:

The issue is just mod related, setting GO111MODULE=on will create this issue. I've tried wiping out the cache (using go clean -cache -modcache ) and when doing go fmt I get this:

$ go fmt

go: creating new go.mod: module consultent/noodle-node go: finding github.com/rburmorrison/go-argue latest go: finding github.com/mattn/go-isatty v0.0.8 go: finding github.com/keimoon/gore latest go: finding github.com/mattn/go-runewidth v0.0.4 go: finding github.com/mattn/go-colorable v0.1.2 go: finding github.com/mattn/go-sqlite3 v1.10.0 go: finding github.com/cheggaaa/pb v2.0.6+incompatible go: downloading github.com/cheggaaa/pb v2.0.6+incompatible go: extracting github.com/cheggaaa/pb v2.0.6+incompatible go: downloading github.com/mattn/go-colorable v0.1.2 go: downloading github.com/mattn/go-isatty v0.0.8 go: extracting github.com/mattn/go-colorable v0.1.2 go: extracting github.com/mattn/go-isatty v0.0.8 go: downloading github.com/mattn/go-runewidth v0.0.4 go: downloading github.com/rburmorrison/go-argue v0.0.0-20190107184430-e164876050e3 go: extracting github.com/mattn/go-runewidth v0.0.4 go: extracting github.com/rburmorrison/go-argue v0.0.0-20190107184430-e164876050e3 go: downloading github.com/keimoon/gore v0.0.0-20160317032603-1ac8b93b5fdb go: extracting github.com/keimoon/gore v0.0.0-20160317032603-1ac8b93b5fdb go: downloading github.com/mattn/go-sqlite3 v1.10.0 go: extracting github.com/mattn/go-sqlite3 v1.10.0 go: finding golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 go: finding gopkg.in/fatih/color.v1 v1.7.0 go: finding gopkg.in/mattn/go-runewidth.v0 v0.0.4 go: finding gopkg.in/VividCortex/ewma.v1 v1.1.1 go: finding gopkg.in/mattn/go-colorable.v0 v0.1.2 go: finding gopkg.in/mattn/go-isatty.v0 v0.0.8 go: finding gopkg.in/cheggaaa/pb.v2 v2.0.6 go: downloading gopkg.in/VividCortex/ewma.v1 v1.1.1 go: extracting gopkg.in/VividCortex/ewma.v1 v1.1.1 go: downloading gopkg.in/mattn/go-colorable.v0 v0.1.2 go: downloading gopkg.in/mattn/go-runewidth.v0 v0.0.4 go: extracting gopkg.in/mattn/go-runewidth.v0 v0.0.4 go: downloading gopkg.in/mattn/go-isatty.v0 v0.0.8 go: downloading gopkg.in/cheggaaa/pb.v2 v2.0.6 go: extracting gopkg.in/cheggaaa/pb.v2 v2.0.6 go: downloading gopkg.in/fatih/color.v1 v1.7.0 go: extracting gopkg.in/fatih/color.v1 v1.7.0 build consultent/noodle-node: cannot load gopkg.in/mattn/go-colorable.v0: cannot find module providing package gopkg.in/mattn/go-colorable.v0

It seems go grabs it from github, but then decides to use gopkg.in

I would like to add that a few months ago, I didn't have this issue (and I tested just now using an earlier version):

These versions have no isssue when used together: go: finding github.com/mattn/go-isatty v0.0.4 go: finding gopkg.in/mattn/go-isatty.v0 v0.0.4 go: finding gopkg.in/mattn/go-colorable.v0 v0.1.0 go: downloading github.com/mattn/go-isatty v0.0.4 go: downloading gopkg.in/mattn/go-isatty.v0 v0.0.4 go: downloading gopkg.in/mattn/go-colorable.v0 v0.1.0 go: extracting github.com/mattn/go-isatty v0.0.4 go: extracting gopkg.in/mattn/go-isatty.v0 v0.0.4 go: extracting gopkg.in/mattn/go-colorable.v0 v0.1.0

azilber avatar Jun 23 '19 11:06 azilber

I just noticed that this was in fact referenced here: https://github.com/mattn/go-colorable/issues/35#issuecomment-475087996

azilber avatar Jun 23 '19 11:06 azilber

@mattn

$ go get gopkg.in/mattn/go-colorable.v0
go: gopkg.in/mattn/[email protected]: parsing go.mod: missing module line
go: error loading module requirements
$ go get gopkg.in/mattn/go-colorable
go: finding gopkg.in latest
go get gopkg.in/mattn/go-colorable: malformed module path "gopkg.in/mattn/go-colorable": invalid version
$ env | grep -e "^GO"
GOBIN=/home/klay/go/bin
GOPROXY=https://goproxy.io
GO111MODULE=on
GOPATH=/home/klay/go
$ go version
go version go1.12.7 linux/amd64

sergeyklay avatar Jul 11 '19 06:07 sergeyklay

Here is a list of modules which incorrectly import this module via gopkg.in: https://pkg.go.dev/gopkg.in/mattn/go-colorable.v0?tab=importedby

All of them are old forks of github.com/cheegaaa/pb.

The issue in pb has been fixed by https://github.com/cheggaaa/pb/pull/146

dolmen avatar Mar 22 '23 11:03 dolmen

@mattn Nobody reported on this issue for 3 years. It can be closed.

dolmen avatar Mar 22 '23 11:03 dolmen