Gin: use gin v1.4.0 build error ambiguous import

Created on 13 May 2019  路  9Comments  路  Source: gin-gonic/gin

  • 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.12.5

  • gin version (or commit ref):
    github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ= github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
  • operating system: ubuntu 18.04

Description

When I update gin to v1.4.0 build error:

build myproject: 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/harrison/Dropbox/project/go_path/pkg/mod/github.com/ugorji/[email protected]/codec)
        github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 (/home/harrison/Dropbox/project/go_path/pkg/mod/github.com/ugorji/go/[email protected])
Makefile:15: recipe for target 'server' failed

I google this error got this ugorji/go#279

Screenshots

Most helpful comment

Yeah, as far as I can tell the problem is:

  • ugorji used to treat /go/codec as a separate module
  • some projects (like viper) depended on that module
  • ugorji then removed the specific module for /go/codec, making /codec accessible through the /go module instead.
  • Gin depended on the latest version of ugorji.
  • We hapless few imported both Gin and viper.

So now when /go/codec is imported, it doesn鈥檛 know if it should use the old, individual module version, or the new, shared module version. And kerblam.

The replace seems to work fine for me, but I鈥檓 still not sure why I can鈥檛 replace it with the latest ugorji version. It complains about it being imported twice, which doesn鈥檛 seem like an issue to me.

All 9 comments

@HZ89 What was your fix?

@bvisness
add this to go.mod file. but I think it should be added to go.mod of gin, not my project

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

gin v1.4.0 have updated the package https://github.com/gin-gonic/gin/blob/v1.4.0/go.mod

gin v1.4.0 have updated the package https://github.com/gin-gonic/gin/blob/v1.4.0/go.mod

yes, but use this go.mod, go mod tidy will get an ambiguous import.

Yeah, as far as I can tell the problem is:

  • ugorji used to treat /go/codec as a separate module
  • some projects (like viper) depended on that module
  • ugorji then removed the specific module for /go/codec, making /codec accessible through the /go module instead.
  • Gin depended on the latest version of ugorji.
  • We hapless few imported both Gin and viper.

So now when /go/codec is imported, it doesn鈥檛 know if it should use the old, individual module version, or the new, shared module version. And kerblam.

The replace seems to work fine for me, but I鈥檓 still not sure why I can鈥檛 replace it with the latest ugorji version. It complains about it being imported twice, which doesn鈥檛 seem like an issue to me.

@HZ89 thanks! this is solve my problem

Hi folks,

Please see https://github.com/ugorji/go/issues/299 and add your thoughts/ideas/etc. Thanks.

why cannot just remove "github.com/ugorji/go v1.1.4"?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilee picture lilee  路  3Comments

ghost picture ghost  路  3Comments

mdnight picture mdnight  路  3Comments

olegsobchuk picture olegsobchuk  路  3Comments

gplume picture gplume  路  3Comments