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: build.Import function doesn't respect go.mod #28192

Closed
go101 opened this issue Oct 13, 2018 · 1 comment
Closed

go/build: build.Import function doesn't respect go.mod #28192

go101 opened this issue Oct 13, 2018 · 1 comment

Comments

@go101
Copy link

go101 commented Oct 13, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

if pkg, err := build.Import(pkgpath, "", build.FindOnly); err != nil {
	log.Print(err)
}

where pkgpath is the import path of a local package in a project supporting modules.
The project is outside GOPATHs.

What did you expect to see?

No errors.

The package can be loaded with conf.Check.

What did you see instead?

cannot find package "github.com/ghuser/myproject/foo" in any of:
	/home/username/sdks/go/src/github.com/ghuser/myproject/foo (from $GOROOT)
	/home/username/go/src/github.com/ghuser/myproject/foo (from $GOPATH)
@myitcv myitcv added the modules label Oct 15, 2018
@myitcv
Copy link
Member

myitcv commented Oct 15, 2018

@go101 - this is happening because you are supplying an empty srcDir as your second argument.

go/packages provides complete support for Go modules and is recognised as the module-aware replacement for go/build (as well as go/loader).

I'll close this therefore but please shout if go/packages doesn't fit your use case because @ianthehat and team will be interested to hear more about that.

@myitcv myitcv closed this as completed Oct 15, 2018
@golang golang locked and limited conversation to collaborators Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants