-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
What version of Go are you using (go version
)?
go version go1.11.1 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env
)?
At least amd64/darwin and amd64/linux, probably all of them.
What did you do?
If a module is just a wrapper for other packages some commands fail
unexpectedly. They also fail with error messages which are not really
helpful diagnosing the underlying problem.
I set up a module which is just a wrapper around two packages a and b
versioned together:
$ tree
.
├── a
│ └── a.go
├── b
│ └── b.go
└── go.mod
$ cat go.mod
module path/should/not/matter
Doing a go build ./...
and works fine but go build
results in
can't load package: package path/should/not/matter: unknown import path "path/should/not/matter": cannot find module providing package path/should/not/matter
Other commands like go clean -modcache
result in the same error.
I think the error can be explained like this:
go build
orgo clean -modcache
are likego build .
orgo clean -modcache .
- Looking up the what
.
stands for in go.mod yields "path/should/not/matter" - The go tool doesn't know what to do with this import path.
(BTW: if the module is e.g. git.intern.ourcorp.net/shared/tooling
the go tool will start queryingFetching https://git.intern.ourcorp.net/shared?go-get=1
to no avail.)
What did you expect to see?
I would expect that a GO111MODULE=on go build
fails with the same
error message like a GO111MODULE=off go build
in a GOPATH layout
namely:
can't load package: package stuff: no Go files in $GOPATH/src/stuff
To reproduce:
$ cd /tmp
$ mkdir stuff
$ cd stuff/
$ mkdir a b
$ echo -e 'package a\nconst S="Package A"' > a/a.go
$ echo -e 'package b\nconst S="Package B"' > b/b.go
$ go mod init "path/should/not/matter"
go: creating new go.mod: module path/should/not/matter
$ go build ./... # fine
$ go clean -modcache
can't load package: package path/should/not/matter: unknown import path "path/should/not/matter": cannot find module providing package path/should/not/matter
$ go build .
can't load package: package path/should/not/matter: unknown import path "path/should/not/matter": cannot find module providing package path/should/not/matter