Skip to content

go.mod placement introduces an ambiguous import error #279

@bcmills

Description

@bcmills

The go.mod file introduced for #259 effectively splits the ugorji/go repository into two separate modules: github.com/ugorji/go and github.com/ugorji/go/codec.

A repository without a go.mod file is effectively a single module, so prior to the introduction of that file, the latest tagged version (v1.1.1) had all of the packages in module github.com/ugorji/go, and some existing users already depended on that module (https://github.com/etcd-io/etcd/blob/329be66e8b3f9e2e6af83c123ff89297e49ebd15/go.mod#L45).

Now, if some program combines those existing users with a user of the new module, they receive two distinct copies of each package (via the two distinct modules), and the build fails with an ambiguous import error:

scratch$ go mod init golang.org/issue/scratch
go: creating new go.mod: module golang.org/issue/scratch

scratch$ go get -m github.com/ugorji/go@latest
go: finding github.com/ugorji/go v1.1.1

scratch$ go get -m github.com/ugorji/go/codec@latest
go: finding github.com/ugorji/go/codec latest

scratch$ go list github.com/ugorji/go/...
go: downloading github.com/ugorji/go v1.1.1
go: extracting github.com/ugorji/go v1.1.1
go: downloading github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2
go: extracting github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2
can't load package: package github.com/ugorji/go/codec: 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 (/tmp/tmp.m35NK6Fpqr/_gopath/pkg/mod/github.com/ugorji/[email protected]/codec)
        github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/tmp/tmp.m35NK6Fpqr/_gopath/pkg/mod/github.com/ugorji/go/[email protected])
can't load package: package github.com/ugorji/go/codec/codecgen: unknown import path "github.com/ugorji/go/codec/codecgen": ambiguous import: found github.com/ugorji/go/codec/codecgen in multiple modules:
        github.com/ugorji/go v1.1.1 (/tmp/tmp.m35NK6Fpqr/_gopath/pkg/mod/github.com/ugorji/[email protected]/codec/codecgen)
        github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/tmp/tmp.m35NK6Fpqr/_gopath/pkg/mod/github.com/ugorji/go/[email protected]/codecgen)

To resolve this problem, I recommend that you add the following line to github.com/ugorji/go/codec/go.mod:

require github.com/ugorji/go v1.1.2-0.20180831062425-e253f1f20942

Until golang/go#27899 is resolved, you may need to re-add the line whenever you run go mod tidy, or add another .go source file to ensure that it is not removed (as described in golang/go#27899 (comment)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions