Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Tools install into open workspace if go.mod present #1919

Closed
FiloSottile opened this issue Sep 8, 2018 · 5 comments
Closed

Tools install into open workspace if go.mod present #1919

FiloSottile opened this issue Sep 8, 2018 · 5 comments
Labels
go-modules Related to Go modules

Comments

@FiloSottile
Copy link
Contributor

After upgrading my macOS system Go to 1.11, two tools fail to install.

Installing 2 tools at /Users/filippo/.vscode/gopath/bin
  megacheck
  gotests

Installing honnef.co/go/tools/... FAILED
Installing github.com/cweill/gotests/... FAILED

2 tools failed to install.

megacheck:
Error: Command failed: /usr/local/bin/go get -u -v honnef.co/go/tools/...
Fetching https://honnef.co/go/tools?go-get=1
Parsing meta tags from https://honnef.co/go/tools?go-get=1 (status code 200)
get "honnef.co/go/tools": found meta tag get.metaImport{Prefix:"honnef.co/go/tools", VCS:"git", RepoRoot:"https://github.com/dominikh/go-tools"} at https://honnef.co/go/tools?go-get=1
go: finding honnef.co/go/tools/... latest
Fetching https://honnef.co/go/tools?go-get=1
Parsing meta tags from https://honnef.co/go/tools?go-get=1 (status code 200)
get "honnef.co/go/tools": found meta tag get.metaImport{Prefix:"honnef.co/go/tools", VCS:"git", RepoRoot:"https://github.com/dominikh/go-tools"} at https://honnef.co/go/tools?go-get=1
go: finding honnef.co/go/tools latest
Fetching https://honnef.co/go?go-get=1
Parsing meta tags from https://honnef.co/go?go-get=1 (status code 200)
Fetching https://honnef.co?go-get=1
Parsing meta tags from https://honnef.co?go-get=1 (status code 200)
go get honnef.co/go/tools/...: no matching versions for query "latest"
Fetching https://honnef.co/go/tools?go-get=1
Parsing meta tags from https://honnef.co/go/tools?go-get=1 (status code 200)
get "honnef.co/go/tools": found meta tag get.metaImport{Prefix:"honnef.co/go/tools", VCS:"git", RepoRoot:"https://github.com/dominikh/go-tools"} at https://honnef.co/go/tools?go-get=1
go: finding honnef.co/go/tools/... latest
Fetching https://honnef.co/go/tools?go-get=1
Parsing meta tags from https://honnef.co/go/tools?go-get=1 (status code 200)
get "honnef.co/go/tools": found meta tag get.metaImport{Prefix:"honnef.co/go/tools", VCS:"git", RepoRoot:"https://github.com/dominikh/go-tools"} at https://honnef.co/go/tools?go-get=1
go: finding honnef.co/go/tools latest
Fetching https://honnef.co/go?go-get=1
Parsing meta tags from https://honnef.co/go?go-get=1 (status code 200)
Fetching https://honnef.co?go-get=1
Parsing meta tags from https://honnef.co?go-get=1 (status code 200)
go get honnef.co/go/tools/...: no matching versions for query "latest"

gotests:
Error: Command failed: /usr/local/bin/go get -u -v github.com/cweill/gotests/...
go: finding github.com/cweill/gotests/... latest
Fetching https://github.com?go-get=1
Parsing meta tags from https://github.com?go-get=1 (status code 200)
go get github.com/cweill/gotests/...: no matching versions for query "latest"
go: finding github.com/cweill/gotests/... latest
Fetching https://github.com?go-get=1
Parsing meta tags from https://github.com?go-get=1 (status code 200)
go get github.com/cweill/gotests/...: no matching versions for query "latest"

What's happening is that my currently open workspace has a go.mod file, and go get is run within that, causing it to both enable modules (which make the install fail) and to pollute my go.mod file.

diff --git a/dcbot/go.mod b/dcbot/go.mod
index 0536ed5..e290a9a 100644
--- a/dcbot/go.mod
+++ b/dcbot/go.mod
@@ -1,11 +1,33 @@
 module github.com/FiloSottile/mostly-harmless/dcbot

 require (
        crawshaw.io/sqlite v0.0.0-20180418062123-f0c5f168ad84
+       github.com/acroca/go-symbols v0.0.0-20180523203557-953befd75e22 // indirect
+       github.com/cosiner/argv v0.0.0-20170225145430-13bacc38a0a5 // indirect
+       github.com/davidrjenni/reftools v0.0.0-20180509164333-3813a62570d2 // indirect
+       github.com/derekparker/delve v1.1.0 // indirect
+       github.com/fatih/gomodifytags v0.0.0-20180826164257-7987f52a7108 // indirect
+       github.com/golang/lint v0.0.0-20180702182130-06c8688daad7 // indirect
+       github.com/haya14busa/goplay v1.0.0 // indirect
+       github.com/josharian/impl v0.0.0-20180228163738-3d0f908298c4 // indirect
+       github.com/karrick/godirwalk v1.7.3 // indirect
+       github.com/mattn/go-isatty v0.0.4 // indirect
+       github.com/mdempsky/gocode v0.0.0-20180727200127-00e7f5ac290a // indirect
+       github.com/peterh/liner v1.1.0 // indirect
        github.com/pkg/errors v0.8.0
+       github.com/ramya-rao-a/go-outline v0.0.0-20170803230019-9e9d089bb61a // indirect
        github.com/sirupsen/logrus v1.0.5
+       github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c // indirect
+       github.com/spf13/cobra v0.0.3 // indirect
+       github.com/spf13/pflag v1.0.2 // indirect
+       github.com/uudashr/gopkgs v1.3.2 // indirect
+       github.com/zmb3/gogetdoc v0.0.0-20180522031303-10095872a7c5 // indirect
+       golang.org/x/arch v0.0.0-20180516175055-5de9028c2478 // indirect
        golang.org/x/crypto v0.0.0-20180411161317-d6449816ce06 // indirect
+       golang.org/x/lint v0.0.0-20180702182130-06c8688daad7 // indirect
        golang.org/x/net v0.0.0-20180415214307-500e7a4f953d // indirect
        golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
        golang.org/x/sys v0.0.0-20180414092825-2281fa97ef7b // indirect
+       golang.org/x/tools v0.0.0-20180904205237-0aa4b8830f48 // indirect
+       gopkg.in/yaml.v2 v2.2.1 // indirect
 )

The go get commands that install tools should be run from $GOPATH/src (keeping go.toolsGopath into account) to disable modules.

See also https://github.com/golang/go/wiki/Modules#why-does-installing-a-tool-via-go-get-fail-with-error-cannot-find-main-module for more modules oriented solution.

@ramya-rao-a
Copy link
Contributor

The go get commands that install tools should be run from $GOPATH/src (keeping go.toolsGopath into account) to disable modules.

Setting GO111MODULE to off in the process that is running the go get commands to install the tools should work as well, correct?

@ramya-rao-a
Copy link
Contributor

I've made the change to turn off GO111MODULE in the process that runs the go get commands. Can you follow the instructions in https://github.com/Microsoft/vscode-go/wiki/Use-the-beta-version-of-the-latest-Go-extension and see if the install/update tools command works for you now?

@brunsgaard
Copy link

@ramya-rao-a I followed the instructions and can confirm that you fix is working as intended here.

@ramya-rao-a
Copy link
Contributor

Thanks @brunsgaard!

@dmigwi
Copy link

dmigwi commented Sep 20, 2018

The fix above still hasn't worked for me... I've also discovered that my vscode doesn't refresh the GOROOT variable (at least the path to Go bin doesn't change) until I restart my machine (Mac Seirra Os).

I have opted to install all the tools using go1.10 settings and after all tools have been successfully installed is when I can now change my Go version using gvm to go1.11. The vscode works fine with all the tools installed with go1.10 setting.

go1.11 settings above still doesn't work even with the beta Go extension binary beta version and GO111MODULE set to off.

Actually with the beta binaries version above, the reload button on the Go extension doesn't go away.
After every reload it keeps bring the same message that I should Install Go extension.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
go-modules Related to Go modules
Projects
None yet
Development

No branches or pull requests

4 participants