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/build: Import() fails for packages using modules and version greater than 1 #26433

Closed
joshuarubin opened this issue Jul 18, 2018 · 3 comments
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@joshuarubin
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

tip

Does this issue reproduce with the latest release?

n/a

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

build.Import() returns an error when trying to load a package from a module with version greater than 1.

cannot find package "github.com/foo/bar/v2" in any of:
...

I got to this indirectly through this:

import (
	"go/ast"
	"go/importer"
	"go/types"
)

func foo() {
	cfg := types.Config{
		Importer: importer.For("source", nil),
	}
	_, err := cfg.Check(...)
}

Where cfg.Check returned:

could not import github.com/foo/bar/v2 (cannot find package "github.com/foo/bar/v2" in any of:
...

What did you expect to see?

The go/* packages in the stdlib work the same way as vgo with the ability to load packages from versioned modules.

What did you see instead?

The errors listed above

@bcmills
Copy link
Contributor

bcmills commented Jul 18, 2018

CC: @alandonovan @ianthehat @rsc

@bcmills bcmills added this to the Go1.11 milestone Jul 18, 2018
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 18, 2018
@rsc
Copy link
Contributor

rsc commented Jul 18, 2018

The answer is to use golang.org/x/tools/go/packages, under development now. If you find any problems using that package, please file new issues against it. Thanks very much.

@rsc
Copy link
Contributor

rsc commented Jul 20, 2018

I take it back - that's the long term answer but we can provide a short-term answer. I reopened this as #26504.

@golang golang locked and limited conversation to collaborators Jul 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants