You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/go: go get can't fetch tools with mod=vendor #32502
I tried to install goimports from my home directory.
$ echo $GO111MODULE
on
$ echo $GOFLAGS
-mod=vendor
$ pwd
/home/jaime
$ go get golang.org/x/tools/cmd/goimports
go get: disabled by -mod=vendor
$
What did you expect to see?
I expected the tool to work like it has for years. I expected go get to download and install goimports.
What did you see instead?
I got an error about -mod=vendor being on.
In my environment, we use vendoring. Because Go is moving away from dep and moving towards modules, we've started doing the work to migrate to modules.
A temporary work around for this bug is to do this.
GO111MODULE=off go get golang.org/x/tools/cmd/goimports
Assuming you vendor your tools, you can try go install -mod=vendor golang.org/x/tools/cmd/goimports or go build -mod=vendor golang.org/x/tools/cmd/goimports
Edit: Just realized I misunderstood what you were trying to do
#30240 may make the -mod=vendor unnecessary in the general case.
#30515 tracks some sort of command (probably a flag for go get) to install a binary independent of the current module.
Note that the argument to go get is a package, and go get some/package implicitly selects the latest version. That version can be arbitrarily different from what is in the vendor directory, so go get -mod=vendor really does seem like a contradictory command.
On the other hand, go get -mod=readonly intentionally ignores the -mod flag, precisely so that you can set it in GOFLAGS. Perhaps go get -mod=vendor should do the same.
I ran into this problem recently where a CI build was installing github.com/golang/gomock/mockgen so that we could run go generate to confirm any generated files were in sync. However as a newer version of gomock was released, this started updating go.mod with the new version rather than sticking with what was pinned in our go.mod.
Seems the solution was to switch to go install github.com/golang/gomock as we always run go mod download && go mod vendor beforehand and this seems to use the pinned version, or at least doesn't update go.mod. I'm not sure it this is entirely correct, but posting in case someone else stumbles over this issue and is looking for something to workaround.
Activity
AlexRouSg commentedon Jun 9, 2019
Assuming you vendor your tools, you can trygo install -mod=vendor golang.org/x/tools/cmd/goimportsorgo build -mod=vendor golang.org/x/tools/cmd/goimportsEdit: Just realized I misunderstood what you were trying to do
mazei513 commentedon Jun 10, 2019
This is more of an issue with
-mod=vendor. Possible things you could try are-mod=vendoroff.tools.goin the repo that references the tools you'd want to use.bcmills commentedon Jun 10, 2019
#30240 may make the
-mod=vendorunnecessary in the general case.#30515 tracks some sort of command (probably a flag for
go get) to install a binary independent of the current module.Note that the argument to
go getis a package, andgo get some/packageimplicitly selects thelatestversion. That version can be arbitrarily different from what is in thevendordirectory, sogo get -mod=vendorreally does seem like a contradictory command.On the other hand,
go get -mod=readonlyintentionally ignores the-modflag, precisely so that you can set it inGOFLAGS. Perhapsgo get -mod=vendorshould do the same.gopherbot commentedon Oct 3, 2019
Change https://golang.org/cl/198438 mentions this issue:
cmd/go: remove the -mod flag from 'go get'electrofelix commentedon Feb 27, 2020
I ran into this problem recently where a CI build was installing github.com/golang/gomock/mockgen so that we could run go generate to confirm any generated files were in sync. However as a newer version of gomock was released, this started updating go.mod with the new version rather than sticking with what was pinned in our go.mod.
Seems the solution was to switch to
go install github.com/golang/gomockas we always rungo mod download && go mod vendorbeforehand and this seems to use the pinned version, or at least doesn't update go.mod. I'm not sure it this is entirely correct, but posting in case someone else stumbles over this issue and is looking for something to workaround.