Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got "ambiguous import: found github.com/ugorji/go/codec in multiple modules" after upgraded to latest (1.3.1) #1673

Closed
mytharcher opened this issue Nov 28, 2018 · 28 comments

Comments

@mytharcher
Copy link

  • With issues:

    • Use the search tool before opening a new issue.
    • Please provide source code and commit sha if you found a bug.
    • Review existing issues and provide feedback or react to them.
  • go version: 1.11

  • gin version (or commit ref): v1.3.1-0.20181126150151-b97ccf3a43d2

  • operating system: Mac/Ubuntu

Description

I found a new feature ShouldBindUri in README doc but no any releases contains it. So I install by go mod:

go get github.com/gin-gonic/gin@master

Then the gin version has been updated to v1.3.1-0.20181126150151-b97ccf3a43d2 in go.mod file.

When I run go build I got this error output:

/go/pkg/mod/github.com/gin-gonic/gin@v1.3.1-0.20181126150151-b97ccf3a43d2/binding/msgpack.go:12:2: unknown import path "github.com/ugorji/go/codec": ambiguous import: found github.com/ugorji/go/codec in multiple modules:
	github.com/ugorji/go v1.1.1 (/go/pkg/mod/github.com/ugorji/go@v1.1.1/codec)
	github.com/ugorji/go/codec v0.0.0-20181012064053-8333dd449516 (/go/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181012064053-8333dd449516)

But if I remove the folder /go/pkg/mod/github.com/ugorji/go@v1.1.1/codec everything goes right.

Not sure if this caused by the new version of gin or go mod.

Hope you could help!

Thanks.

@thinkerou
Copy link
Member

@mytharcher sorry, I can not reproduce the issue, my steps:

image

@mytharcher
Copy link
Author

Thanks for help @thinkerou ! I will have a try with the demo you provided. It looks really weird.

@mytharcher
Copy link
Author

At last, I found the answer which is another package depends on the ugorji/go/codec@v0.0.0 explicitly. But seems for now go mod didn't solve the multi version dependency.

@thinkerou
Copy link
Member

But seems for now go mod didn't solve the multi version dependency.

looks like, thanks!

@DenLilleMand
Copy link

Sorry, i have this exact issue trying to convert my server project into using go modules, though i cannot see any other project explicitly depending on this package - and i have the same error as you. I am using the newest v1.3.0.

What moves do i have?

gin-gonic

@zannen
Copy link

zannen commented Jan 24, 2019

I am having a similar problem. Here is my minimal test file (main.go):

package main

import (
	"log"
	"net/http"
	"sync"

	"github.com/gin-contrib/expvar"
	"github.com/gin-gonic/gin"
)
func main() {
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()
		gin.SetMode(gin.ReleaseMode)
		ginrouter := gin.New()
		ginrouter.GET("/debug/vars", expvar.Handler())
		svr := &http.Server{
			Addr:    ":8080",
			Handler: ginrouter,
		}
		if err := svr.ListenAndServe(); err != nil {
			log.Fatal("Could not listen")
		}
	}()
	wg.Wait()
}

There are three things I've tried so far.

One: use go-mod and no go-get

This works fine:

u@h:newproj$ pwd
/home/zannen/go/src/newproj
u@h:newproj$ rm -f go.{mod,sum}
u@h:newproj$ go mod init
go: creating new go.mod: module newproj
u@h:newproj$ go build -o main main.go
go: finding github.com/gin-contrib/expvar latest
u@h:newproj$ cat go.mod 
module newproj

require github.com/gin-contrib/expvar v0.0.0-20181230111036-f23b556cc79f // indirect
u@h:newproj$ ./main &
[1] 23861
u@h:newproj$ curl localhost:8080/debug/vars
{ "cmdline": ["./main"], ... }

Two: use go-get for gin then gin-contrib/expvar

This one fails, mentioning github.com/ugorji/go/codec.

u@h:newproj$ pwd
/home/zannen/go/src/newproj
u@h:newproj$ rm -f go.{mod,sum}
u@h:newproj$ go mod init
go: creating new go.mod: module newproj
u@h:newproj$ go get github.com/gin-gonic/gin@v1.3.1-0.20190118015706-4867ff9634d1
u@h:newproj$ go get github.com/gin-contrib/expvar@v0.0.0-20181230111036-f23b556cc79f
go build github.com/ugorji/go/codec: no Go files in 
u@h:newproj$ # note weird error in the second go-get: gin-contrib/expvar
u@h:newproj$ cat go.mod 
module newproj

require (
	github.com/gin-contrib/expvar v0.0.0-20181230111036-f23b556cc79f // indirect
	github.com/gin-gonic/gin v1.3.1-0.20190118015706-4867ff9634d1 // indirect
)
u@h:newproj$ go build -o main2 main2.go 
../../pkg/mod/github.com/gin-gonic/gin@v1.3.1-0.20190118015706-4867ff9634d1/binding/msgpack.go:12:2: unknown import path "github.com/ugorji/go/codec": ambiguous import: found github.com/ugorji/go/codec in multiple modules:
	github.com/ugorji/go v1.1.1 (/home/zannen/go/pkg/mod/github.com/ugorji/go@v1.1.1/codec)
	github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/home/zannen/go/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181209151446-772ced7fd4c2)

Three: use go-get for gin-contrib/expvar then gin

u@h:newproj$ pwd
/home/zannen/go/src/newproj
u@h:newproj$ rm -f go.{mod,sum}
u@h:newproj$ go mod init
go: creating new go.mod: module newproj
u@h:newproj$ go get github.com/gin-contrib/expvar@v0.0.0-20181230111036-f23b556cc79f
u@h:newproj$ go get github.com/gin-gonic/gin@v1.3.1-0.20190118015706-4867ff9634d1
go build github.com/ugorji/go/codec: no Go files in 
u@h:newproj$ # again, note weird error in the second go-get: gin-gonic/gin
u@h:newproj$ cat go.mod 
module newproj

require (
	github.com/gin-contrib/expvar v0.0.0-20181230111036-f23b556cc79f // indirect
	github.com/gin-gonic/gin v1.3.1-0.20190118015706-4867ff9634d1 // indirect
)
u@h:newproj$ go build -o main main.go 
../../pkg/mod/github.com/gin-gonic/gin@v1.3.1-0.20190118015706-4867ff9634d1/binding/msgpack.go:12:2: unknown import path "github.com/ugorji/go/codec": ambiguous import: found github.com/ugorji/go/codec in multiple modules:
	github.com/ugorji/go v1.1.1 (/home/zannen/go/pkg/mod/github.com/ugorji/go@v1.1.1/codec)
	github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/home/zannen/go/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181209151446-772ced7fd4c2)

Conclusion

I'm still investigating, but I'll have to avoid using gin-contrib/expvar for now.

@solarhell
Copy link

I just meet the same issue. Any solution?

@DenLilleMand
Copy link

I just meet the same issue. Any solution?

Nope. I just gave up converting to go modules, wasn't that important to me

@anymost
Copy link

anymost commented Apr 10, 2019

I just meet the same issue. Any solution?

you need vpn

@gsgtzq
Copy link

gsgtzq commented Apr 11, 2019

I find a way to fix this problem, you can use replace command to set package alias. I added the following code in my go.mod file, it's build success.

replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43

The full go.mod file like this

module myproject

go 1.12

require (
	github.com/coreos/etcd v3.3.12+incompatible // indirect
	github.com/coreos/go-semver v0.3.0 // indirect
	github.com/gin-gonic/gin v1.3.1-0.20190406134833-ffcbe77b1e62
	github.com/golang/protobuf v1.3.1 // indirect
	github.com/jakecoffman/cron v0.0.0-20190106200828-7e2009c226a5
	github.com/json-iterator/go v1.1.6 // indirect
	github.com/mattn/go-isatty v0.0.7 // indirect
	github.com/mitchellh/go-homedir v1.1.0
	github.com/pelletier/go-toml v1.3.0 // indirect
	github.com/spf13/afero v1.2.2 // indirect
	github.com/spf13/cobra v0.0.3
	github.com/spf13/jwalterweatherman v1.1.0 // indirect
	github.com/spf13/viper v1.3.2
	github.com/stretchr/objx v0.2.0 // indirect
        // WARNING: I removed github.com/ugorji/go v1.1.4 //indirect
	go.etcd.io/bbolt v1.3.2
	golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5 // indirect
	golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect
	golang.org/x/sys v0.0.0-20190410235845-0ad05ae3009d // indirect
	golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 // indirect
	gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)

replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43

@knwoop
Copy link

knwoop commented Apr 11, 2019

@gsgtzq Thanks!! I solved the problem .

@stavgayer
Copy link

the dependent repo has changed, please refer to :
ugorji/go@74d13ae

@awkj
Copy link
Contributor

awkj commented May 5, 2019

gin need update ugorji/go go-playground/validator.v8, wait 1.4.0 release .

@thinkerou
Copy link
Member

@awkj please see #1879

@awkj
Copy link
Contributor

awkj commented May 5, 2019

@awkj please see #1879

yes, I know, I am waiting for javierprovecho

@datewu
Copy link

datewu commented May 8, 2019

go get github.com/ugorji/go/codec@none saved my day.
run go get above, before run go build.

golang/go#29332 (comment)

@g00nix
Copy link

g00nix commented May 15, 2019

I tried then solutions above but they didn't work for me. I still get the error:

build cghq/gen4_random-device: 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 (/home/gunix/.go/pkg/mod/github.com/ugorji/go@v1.1.4/codec)
	github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/home/gunix/.go/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181209151446-772ced7fd4c2)

@songkane
Copy link

github.com/ugorji/go/codec

it occurs another problem when using unit test
go: github.com/ugorji/go/codec@v0.0.0-20190320090025-2dc34c0b8780 used for two different module paths (github.com/ugorji/go and github.com/ugorji/go/codec)

@r21gh
Copy link

r21gh commented May 22, 2019

I had same issue, this instruction solved error.

@Frederic-Zhou
Copy link

add this code to go.mod , it was worked

replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43

@ugorji
Copy link

ugorji commented May 23, 2019

Hi folks,

Please see ugorji/go#299 and add your thoughts/ideas/etc. Thanks.

@thinkerou thinkerou reopened this May 24, 2019
@jrefior
Copy link

jrefior commented Jun 14, 2019

This fixed the issue for my repo (leaving off /codec):

go.mod:

replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go v0.0.0-20190204201341-e444a5086c43

@thinkerou
Copy link
Member

If use gin v1.3.0, the go.mod file like this:
(using go get github.com/gin-gonic/gin@v1.3.0)

module github.com/thinkerou/gintest

go 1.12

require (
	github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
	github.com/gin-gonic/gin v1.3.0
	github.com/golang/protobuf v1.3.1 // indirect
	github.com/json-iterator/go v1.1.6 // indirect
	github.com/mattn/go-isatty v0.0.7 // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.1 // indirect
	github.com/stretchr/testify v1.3.0 // indirect
	github.com/ugorji/go v1.1.4 // indirect
	golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c // indirect
	gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
	gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
	gopkg.in/yaml.v2 v2.2.2 // indirect
)

If use gin v1.4.0, the go.mod file like this:
(using go get github.com/gin-gonic/gin@v1.4.0)

module github.com/thinkerou/gintest

go 1.12

require github.com/gin-gonic/gin v1.4.0

so, I suggest to upgrade gin to v1.4.0, thanks!

@walkskyer
Copy link

walkskyer commented Jun 26, 2019

@jrefior Thanks!
go.mod:
replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go v0.0.0-20181022190402-e5e69e061d4f

@ugorji
Copy link

ugorji commented Jul 2, 2019

FYI: I just released a go-codec production release - version 1.1.7 (finally)

First, it resolves the go.mod impasse where we had different import paths (github.com/ugorji/go and github.com/ugorji/go/codec) causing the ambiguous import error.

This is now fixed by leveraging import cycles to ensure that either one works well and resolves to the same bits.

Please let me know if seeing any issues. If all is well over the next few days, I will close this github issue.

@thinkerou
Copy link
Member

@ugorji thanks a lot!

@geckofu
Copy link

geckofu commented Oct 21, 2019

@ugorji Is it possible to release ugorji/go v2, then gin can import it using semantic versioning,
as mentioned in https://blog.golang.org/using-go-modules
:

import (
    ugorji "github.com/ugorji/go/v2"
)

This enforces the use of new code while other projects can still use old versions.

@AmreeshTyagi
Copy link

go get github.com/ugorji/go/codec@none saved my day.
run go get above, before run go build.

golang/go#29332 (comment)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests