gin: Got "ambiguous import: found github.com/ugorji/go/codec in multiple modules" after upgraded to latest (1.3.1)
-
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 20
- Comments: 28 (7 by maintainers)
Commits related to this issue
- updated go.mod; fix to broken dep for ugorji/go/codec as per https://github.com/gin-gonic/gin/issues/1673 — committed to mikepea/m53play by mikepea 5 years ago
- Fix go mod tidy errors and fix platform independent downloads Refer https://github.com/gin-gonic/gin/issues/1673 — committed to harshavardhana/minio by harshavardhana 5 years ago
- Fix go mod tidy errors and fix platform independent downloads (#8222) Refer https://github.com/gin-gonic/gin/issues/1673 — committed to minio/minio by harshavardhana 5 years ago
I find a way to fix this problem, you can use
replacecommand to set package alias. I added the following code in mygo.modfile, it’s build success.The full
go.modfile like thisyou need vpn
go get github.com/ugorji/go/codec@nonesaved my day. rungo getabove, before rungo build.https://github.com/golang/go/issues/29332#issuecomment-448669442
add this code to go.mod , it was worked
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?
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.
This fixed the issue for my repo (leaving off
/codec):go.mod:@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 :
This enforces the use of new code while other projects can still use old versions.
I am having a similar problem. Here is my minimal test file (
main.go):There are three things I’ve tried so far.
One: use go-mod and no go-get
This works fine:
Two: use go-get for gin then gin-contrib/expvar
This one fails, mentioning
github.com/ugorji/go/codec.Three: use go-get for gin-contrib/expvar then gin
Conclusion
I’m still investigating, but I’ll have to avoid using
gin-contrib/expvarfor now.@jrefior Thanks! go.mod: replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go v0.0.0-20181022190402-e5e69e061d4f
If use
gin v1.3.0, thego.modfile like this: (usinggo get github.com/gin-gonic/gin@v1.3.0)If use
gin v1.4.0, thego.modfile like this: (usinggo get github.com/gin-gonic/gin@v1.4.0)so, I suggest to upgrade gin to
v1.4.0, thanks!