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: "no required module provides package" is confusing for paths under the current module #44961

mvdan opened this issue Mar 12, 2021 · 7 comments
GoCommand modules NeedsFix okay-after-beta1


Copy link

@mvdan mvdan commented Mar 12, 2021

Using as an example:

$ go version
go version devel +cf59850466 Wed Mar 10 09:01:05 2021 +0000 linux/amd64
$ cd tools
$ git checkout -q 44abc2a71b321b77c0a579d8c5bf2704d648c9e0
$ cd cmd/benchcmp
$ sed -i 's@benchmark/parse@missing/package@g' *.go
$ go build
benchcmp.go:15:2: no required module provides package; to add it:
	go get
$ go get
go get no matching versions for query "upgrade"

What I do here is add an import to a missing package that could be part of the current main module. The example I use is perhaps silly, but it's somewhat common to end up in this situation. For example:

  • Rebasing or applying an old patch that imports a package which is now moved or deleted
  • Writing an import manually and making a typo

I get why the errors are technically correct. When I run go build, the go tool doesn't know if there happens to be a module with path or, which could possibly contain the package needed. And, when I run the go get, it finds no such module, and the main module can't be upgraded to contain such a package.

First, an assumption: nested Go modules are very rare, and should not be encouraged. So I don't think that we should be optimizing the error messages for that use case.

Now, some suggestions from the user's point of view, for this scenario:

  1. The go build error shouldn't suggest go get. It's very unlikely that it will fix the problem. If the user really has nested modules that would be fixed with a go get, I imagine they know what they're doing and can figure out what to do.

For example, here's a suggestion:

$ go build
benchcmp.go:15:2: package does not exist in the main module
  1. The go get error is confusing. For example, see what happens if I try to upgrade the main module:
$ go get -d
go get: can't request version "latest" of the main module (

Now, compare that with package paths:

$ go get -d
go get no matching versions for query "upgrade"
$ go get -d
go get no matching versions for query "latest"

If no nested module is found, I think it should just show the can't request version error, just like go get -d

@jayconrod jayconrod added the NeedsFix label Mar 12, 2021
@jayconrod jayconrod added this to the Go1.17 milestone Mar 12, 2021
Copy link

@jayconrod jayconrod commented Mar 12, 2021

While the error message is technically correct (the package could be in another module with a longer path, and go get might add the correct requirement), it's far more likely that the package just doesn't exist. I agree that your proposed go build error message is better. The go get messages seem like they could be improved, too.

@jayconrod jayconrod added the okay-after-beta1 label May 17, 2021
Copy link

@gopherbot gopherbot commented Jun 5, 2021

Change mentions this issue: cmd/go: improve "invalid version" error messages

Copy link

@bcmills bcmills commented Jun 7, 2021

Compare #33568.

@jayconrod jayconrod removed this from the Go1.17 milestone Jul 29, 2021
@jayconrod jayconrod added this to the Go1.18 milestone Jul 29, 2021
Copy link

@ianlancetaylor ianlancetaylor commented Nov 18, 2021

This is in the Go1.18 milestone. Is it likely to happen for 1.18? Thanks.

Copy link

@ianlancetaylor ianlancetaylor commented Jan 28, 2022

@bcmills This is in the 1.18 milestone; time to move to 1.19? Thanks.

@bcmills bcmills removed this from the Go1.18 milestone Jan 28, 2022
@bcmills bcmills added this to the Backlog milestone Jan 28, 2022

This comment was marked as duplicate.

Copy link

@iwdgo iwdgo commented May 14, 2022

Issue seems solved. It is difficult to locate which commit but on go1.18 with the case filed, the message is more explicit. The reference to go get is replaced by the import causing the error (missing/path in this case).

GOPATH\golang\x\tools\cmd\benchcmp>go version
go version go1.18.1 windows/amd64

GOPATH\golang\x\tools\cmd\benchcmp>set GO111MODULE

GOPATH\golang\x\tools\cmd\benchcmp>go build
code in directory C:\Users\Costa\Documents\Google\golang\x\tools\cmd\benchcmp expects import "
benchcmp.go:10:2: cannot find package "missing/path" in any of:
        C:\Program Files\Go\src\missing\path (from $GOROOT)
        C:\Users\Costa\Documents\Google\src\missing\path (from $GOPATH)

GOPATH\golang\x\tools\cmd\benchcmp>set GO111MODULE=

GOPATH\Google\golang\x\tools\cmd\benchcmp>go build
benchcmp.go:10:2: cannot find package "." in:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
GoCommand modules NeedsFix okay-after-beta1
None yet

No branches or pull requests

6 participants