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

cmd/go: poor error message from 'go build -mod=vendor' when passing an absolute package path instead of a relative one #38748

bcmills opened this issue Apr 29, 2020 · 3 comments


Copy link

@bcmills bcmills commented Apr 29, 2020

When foo is a relative subdirectory, the error message from go build foo/ seems a lot worse when -mod=vendor is set than when it is unset:$ go version
go version devel +e1a96b82 Wed Apr 29 08:57:33 2020 +0000 linux/amd64$ go build ./foo$ go build foo/
package foo is not in GOROOT (/usr/local/google/home/bcmills/sdk/gotip/src/foo)$ go build -mod=vendor foo/
package foo: cannot find package "." in:

-- foo/foo.go --
package foo
-- go.mod --

go 1.15

The error message from the first go build foo/ seems reasonable to me: it clearly indicates that foo was interpreted as a package path, where we expected to find that package, and why we failed to do so.

The error message from go build -mod=vendor foo/ is much worse: it mentions a package ".", which has nothing to do with what the user passed in, fails to mention GOROOT (which is where a package named foo generally ought to be) at all, and buries the vendor part in the middle of the file path.

CC @jayconrod @matloob

Copy link

@justplesh justplesh commented Jun 4, 2020

I will work on it!

Copy link

@nikhita nikhita commented Jul 8, 2020

@bcmills We came across a similar error message in Kubernetes, though I'm not too sure if it's due to the same reason as mentioned in the issue body.

Running the following command at the root of worked in go 1.13 but fails in go 1.14. kubernetes/test-infra#18200 has more details.

The repo is at

With go 1.14.4:

$ go run ./staging/publishing/rules.yaml
package cannot find package "." in:

With go 1.13.12:

$ go run ./staging/publishing/rules.yaml
go: finding latest
I0708 03:03:16.384590   14888 rules.go:89] loading rules file : ./staging/publishing/rules.yaml
I0708 03:03:16.395696   14888 rules.go:125] validating repository order
I0708 03:03:16.395848   14888 main.go:37] validation successful

cc @dims @liggitt

Copy link

@jayconrod jayconrod commented Jul 8, 2020

@nikhita Can confirm, that issue is closely related.

go mod vendor copies into the vendor directory packages needed to build packages in the main module and their tests. Since is not imported by any package in the main module, it won't be vendored.

This error is shown when vendor mode is enabled and a package that's not present in the vendor directory is needed. In Go 1.14, vendor mode is enabled when vendor/modules.txt is in sync with go.mod and go.mod has go 1.14 or higher.

As a work around, you can import from a "tools" package that is never built, then run go mod vendor again. It looks like hack/tools/tools.go and build/tools.go are already used to track a few tools like this. You can also use the -mod=mod flag to build without the vendor directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants