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 · 23 comments

Comments

Projects
None yet
@mytharcher
Copy link

commented Nov 28, 2018

  • 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

This comment has been minimized.

Copy link
Member

commented Nov 28, 2018

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

image

@mytharcher

This comment has been minimized.

Copy link
Author

commented Nov 29, 2018

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

@mytharcher

This comment has been minimized.

Copy link
Author

commented Nov 29, 2018

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.

@mytharcher mytharcher closed this Nov 29, 2018

@thinkerou

This comment has been minimized.

Copy link
Member

commented Nov 29, 2018

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

looks like, thanks!

@DenLilleMand

This comment has been minimized.

Copy link

commented Jan 21, 2019

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Mar 6, 2019

I just meet the same issue. Any solution?

@DenLilleMand

This comment has been minimized.

Copy link

commented Mar 6, 2019

I just meet the same issue. Any solution?

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

@anymost

This comment has been minimized.

Copy link

commented Apr 10, 2019

I just meet the same issue. Any solution?

you need vpn

@gsgtzq

This comment has been minimized.

Copy link

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

@takahashi-ke

This comment has been minimized.

Copy link

commented Apr 11, 2019

@gsgtzq Thanks!! I solved the problem .

@stavgayer

This comment has been minimized.

Copy link

commented Apr 23, 2019

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

@awkj

This comment has been minimized.

Copy link
Contributor

commented May 5, 2019

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

@thinkerou

This comment has been minimized.

Copy link
Member

commented May 5, 2019

@awkj please see #1879

@awkj

This comment has been minimized.

Copy link
Contributor

commented May 5, 2019

@awkj please see #1879

yes, I know, I am waiting for javierprovecho

@sinalpha

This comment has been minimized.

Copy link

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)

@gun1x

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented May 17, 2019

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)

@RezaGhanbari

This comment has been minimized.

Copy link

commented May 22, 2019

I had same issue, this instruction solved error.

@ZetaChow

This comment has been minimized.

Copy link

commented May 22, 2019

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

This comment has been minimized.

Copy link

commented May 23, 2019

Hi folks,

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

@jrefior

This comment has been minimized.

Copy link

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 thinkerou referenced this issue Jun 17, 2019

Closed

use go mod #79

@thinkerou

This comment has been minimized.

Copy link
Member

commented Jun 17, 2019

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!

@thinkerou thinkerou closed this Jun 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.