golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.63k stars 17.61k forks source link

cmd/go: ambiguous error message on ambiguous import #32128

Open jerome-laforge opened 5 years ago

jerome-laforge commented 5 years ago

What version of Go are you using (go version)?

1.12

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build116507160=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I deal with a problem of ambiguous module import when I try to import github.com/spf13/viper@1.3.2 and github.com/gin-gonic/gin@v1.4.0

https://play.golang.org/p/NwzVwWsOjbO

What did you expect to see?

@thepudds (thx to him for his support) has advised me to open a issue to have clearer diagnostic message or a simpler solution.

the proposed solution, that works for me, is: go get github.com/ugorji/go/codec@none

https://groups.google.com/forum/#!topic/golang-nuts/0mJh8SkaomA

jayconrod commented 5 years ago

For reference, the error message is:

build testmod: cannot load github.com/ugorji/go/codec: ambiguous import: found github.com/ugorji/go/codec in multiple modules:
    github.com/ugorji/go v1.1.4 (/tmp/gopath660937702/pkg/mod/github.com/ugorji/go@v1.1.4/codec)
    github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 (/tmp/gopath660937702/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8)

The two modules don't require each other at versions that would avoid the ambiguous import.

It's hard to capture all this in an error message, but we might recommend requiring specific versions of these modules to avoid the ambiguous import.

Related #27899

bcmills commented 5 years ago

It's hard to capture all this in an error message, but we might recommend requiring specific versions of these modules to avoid the ambiguous import.

I think if we can recommend an upgrade that resolves the ambiguous import, we should just apply it instead of telling the user to apply it.

bcmills commented 5 years ago

the proposed solution, that works for me, is: go get github.com/ugorji/go/codec@none

I note that this issue predates the resolution of https://github.com/ugorji/go/issues/299.

With that resolved, go get github.com/ugorji/go/codec@latest should also resolve the problem with the module graph. (The versions in the example are still incompatible, but due to breaking API changes rather than an ambiguous import path: https://play.golang.org/p/YXT3Pc69yYM.)

thepudds commented 5 years ago

For the errors in that playground link, I believe at least one set of the errors is due to fsnotify not supporting nacl/amd64p32.

That might explain all the errors there.

gopherbot commented 5 years ago

Change https://golang.org/cl/196298 mentions this issue: cmd/go/internal/modload: use a structured error for 'ambiguous import'

harshakp06 commented 8 months ago

Any way to resolve -- ambiguous import: found package time in multiple modules: ??