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

go.mod placement introduces an ambiguous import error #279

Closed
bcmills opened this issue Jan 25, 2019 · 7 comments
Closed

go.mod placement introduces an ambiguous import error #279

bcmills opened this issue Jan 25, 2019 · 7 comments

Comments

@bcmills
Copy link

bcmills commented Jan 25, 2019

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/go@v1.1.1/codec)
        github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/tmp/tmp.m35NK6Fpqr/_gopath/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181209151446-772ced7fd4c2)
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/go@v1.1.1/codec/codecgen)
        github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 (/tmp/tmp.m35NK6Fpqr/_gopath/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181209151446-772ced7fd4c2/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)).

@bcmills
Copy link
Author

bcmills commented Jan 25, 2019

As a workaround in the interim, anyone running into the ambiguous import error can apply the fix themselves by running

go get github.com/ugorji/go@v1.1.2-0.20180831062425-e253f1f20942

@ugorji
Copy link
Owner

ugorji commented Jan 26, 2019

why v1.1.2-XXX ? I am a big confused, and I don't want to make assumptions.

@ugorji
Copy link
Owner

ugorji commented Jan 26, 2019

As a workaround in the interim, anyone running into the ambiguous import error can apply the fix themselves by running

go get github.com/ugorji/go@v1.1.2-0.20180831062425-e253f1f20942

I don't understand why this works? There's no tag v1.1.2. Is this a git thing, and if so, can you explain?

I truly don't understand the quirks of modules yet. I just want to support a multi-module repo, which is what I had been wanting from the beginning, and this feels like the best time to get it setup. I want folks to treat github.com/ugorji/go/codec as a module in itself (not github.com/ugorji/go)

ugorji added a commit that referenced this issue Jan 26, 2019
This should workaround the ambiguous import errors using modules.

It requires that we tag a new release right after this change (as v1.1.2)

Hope it works

Updates #279
@ugorji
Copy link
Owner

ugorji commented Jan 26, 2019

This should be fixed now, as at 8fd0f8d . Please let me know if this is fixed for you.

@ugorji ugorji closed this as completed Jan 26, 2019
@bcmills
Copy link
Author

bcmills commented Jan 26, 2019

Thanks for the fix!

why v1.1.2-XXX ?

That's the pseudo-version at which the packages were removed from the root module, so that requirement ensures that only the github.com/ugorji/go/codec module provides those packages.

eliben added a commit to google/go-cloud that referenced this issue May 13, 2019
…#2057)

Updates #2048 - moves the go.mod file from samples/appengine to samples.

Note the replace gocloud.dev => ../ added to the go.mod. Without this, running go test ./... in samples/ results in many errors like:

can't load package: package gocloud.dev/samples/server: unknown import path "gocloud.dev/samples/server": ambiguous import: found gocloud.dev/samples/server in multiple modules:
	gocloud.dev/samples (/home/eliben/eli/go-cloud/samples/server)
	gocloud.dev v0.13.0 (/home/eliben/eli/go/pkg/mod/gocloud.dev@v0.13.0/samples/server)

The symptom and solution is explained by bcmills in ugorji/go#279 (which refers also to golang/go#27899). The new go.mod points to gocloud.dev v0.13, which also provides these packages - so the go command is confused - it sees the same package(s) provided by two different modules.

The ugorji/go solution was to use a pseudo-version pointing at an existing commit in the core module which removes the packages - this removes the ambiguity. In our case, there is no existing commit yet - so I'm using a replace line. The replace line should be unnecessary when we release a new CDK version.

This has interesting implications for #886 - we'll likely have to do the same when we split out providers to their own modules and retain replace lines until a new release.
@ugorji
Copy link
Owner

ugorji commented May 23, 2019

Hi folks,

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

@ugorji
Copy link
Owner

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.

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

2 participants