Vscode: VS Code unable to locate Go tools on my MacBook

Created on 2 Oct 2020  ·  23Comments  ·  Source: microsoft/vscode




  • VSCode Version:
    Version: 1.49.3
    Commit: 2af051012b66169dde0c4dfae3f5ef48f787ff69
    Date: 2020-10-02T17:54:06.165Z
    Electron: 9.2.1
    Chrome: 83.0.4103.122
    Node.js: 12.14.1
    V8: 8.3.110.13-electron.0
  • OS Version: Darwin x64 18.7.0
  • Go Extension Version: 0.17.2

Steps to Reproduce:

  1. Close all VS Code windows
  2. Launch VS Code by clicking on a pinned shortcut in the Dock

I get the error below:
image

While troubleshooting locally, I used the _Go: Locate Configured Go Tools_ command from the Go Extension and it showed the following:

Checking configured tools....
GOBIN: undefined
toolsGopath: undefined
gopath: undefined
GOROOT: 
PATH: /usr/bin:/bin:/usr/sbin:/sbin

unable to locate "go" binary in GOROOT () or PATH (/usr/bin:/bin:/usr/sbin:/sbin)
unable to locate "go" binary in GOROOT () or PATH (/usr/bin:/bin:/usr/sbin:/sbin)

When I launch VS Code by running code from a terminal session the error message does not occur and the _Go: Locate Configured Go Tools_ command correctly finds the Go tools.

Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /Users/dbourque/dev/golang
GOROOT: /usr/local/Cellar/go/1.15.2/libexec
PATH: [redacted]

   gocode: /Users/dbourque/dev/golang/bin/gocode installed
   gopkgs: /Users/dbourque/dev/golang/bin/gopkgs installed
   go-outline: /Users/dbourque/dev/golang/bin/go-outline installed
   go-symbols: /Users/dbourque/dev/golang/bin/go-symbols installed
   guru: /Users/dbourque/dev/golang/bin/guru installed
   gorename: /Users/dbourque/dev/golang/bin/gorename installed
   gotests: /Users/dbourque/dev/golang/bin/gotests installed
   gomodifytags: /Users/dbourque/dev/golang/bin/gomodifytags installed
   impl: /Users/dbourque/dev/golang/bin/impl installed
   fillstruct: /Users/dbourque/dev/golang/bin/fillstruct installed
   goplay: /Users/dbourque/dev/golang/bin/goplay installed
   godoctor: /Users/dbourque/dev/golang/bin/godoctor installed
   dlv: /Users/dbourque/dev/golang/bin/dlv installed
   gocode-gomod: /Users/dbourque/dev/golang/bin/gocode-gomod installed
   godef: /Users/dbourque/dev/golang/bin/godef installed
   goimports: /Users/dbourque/dev/golang/bin/goimports installed
   golangci-lint: /Users/dbourque/dev/golang/bin/golangci-lint installed
   gopls: /Users/dbourque/dev/golang/bin/gopls installed

go env
Workspace Folder (tryitout): /Users/dbourque/dev/tryitout
    GO111MODULE=""
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/Users/dbourque/Library/Caches/go-build"
    GOENV="/Users/dbourque/Library/Application Support/go/env"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOINSECURE=""
    GOMODCACHE="/Users/dbourque/dev/golang/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="darwin"
    GOPATH="/Users/dbourque/dev/golang"
    GOPRIVATE=""
    GOPROXY=""
    GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
    GOSUMDB="off"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
    GCCGO="gccgo"
    AR="ar"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    GOMOD="/Users/dbourque/dev/tryitout/go.mod"
    CGO_CFLAGS=""
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="/usr/local/bin/pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3t/4048hqr5459dw83ksmkqxn7r0000gn/T/go-build186798659=/tmp/go-build -gno-record-gcc-switches -fno-common"


Does this issue occur when all extensions are disabled?: No

This issue for the Go Extension generated the same error message but this fix for it does not correct the behavior for me.

needs more info

Most helpful comment

No worries @CanRau , I stole the idea from the depths of another github issue thread and have to do the same for all of my windows. Luckily not all of them need the full environment!

All 23 comments

The PATH value is what the vscode gave to the extension. You can verify what PATH value vscode sees by

1) launching vscode from dock (not from your terminal), and disabling the go extension,
2) opening Developer: Toggle Developer Tools and
3) querying process.env['PATH'] from the developer tool console.

@dylan-bourque What does it say?

FYI, this is different from golang/vscode-go#713.

Edit: I edited my msg a bit so vscode team can see the issue more clearly, not distracted by the go issue :-)

This fixed it for me

  1. follow the instructions here to set GOPATH, GOROOT & PATH. NOTE: I didn't use the install.sh script!
  2. Close & open VSCode
  3. Disable & re-enable vscode-go plugin
  4. Hit Update on the notification popping up talking about a changed GOROOT

@hyangah process.env['PATH'] returns:

"/Users/dbourque/.pyenv/shims:/usr/local/opt/gnu-sed/libexec/gnubin:/Users/dbourque/.nvm/versions/node/v14.4.0/bin:/usr/local/opt/make/libexec/gnubin:/Users/dbourque/dev/golang/bin:/Users/dbourque/bin:/Users/dbourque/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/dbourque/Library/Python/2.7/bin"

I see here that /usr/local/bin is actually included and that is where my go binary is installed (by Brew). A bit strangely, $GOPATH is set to $HOME/dev/golang and $GOPATH/bin is added to $PATH in ~/.bashrc and that is included, even though one suggestion was that the problem is that the editor only reads .profile, .bash_profile and .zprofile on a Mac.

@CanRau I already have my environment configuration in ~/.bashrc like that link suggests.

As I've said, none of my "profile" files (~/.profile, ~/.bash_profile, ~/.zprofile, ~/.bashrc, ~/.zshrc) have changed at all. My environment (both login and interactive shells) is the same as it was 2 months ago when I was not seeing this error.

I am still not convinced that this is a VS Code issue

From my standpoint, $GOROOT has never been set and $PATH has never included my Go installation based on just my .profile, .bash_profile and .zprofile environment. That environment configuration has been added in my .bashrc since I've had this machine (roughly a year) and this error message at startup is new (within the last few weeks). If I launch the editor from an open terminal (by running code) the error does not occur.

It appears that the Go extension is getting a system-default $PATH (only /usr/bin:/bin:/usr/sbin:/sbin) despite process.env['PATH'] containing additional directories (including /usr/local/bin which is where Go is installed).

It's really strange that vscode-go sees a different process.env['PATH'] - the following is where the process.env['PATH'] is picked up in the go extension https://github.com/golang/vscode-go/blob/70f7a71e6bb85c987eefaca069185624f4c7168a/src/utils/pathUtils.ts#L20)

Note that the value is cached and it's initialized only once.

One possibility is that the process.env['PATH'] was changed after the go extension was initialized I think.

@dylan-bourque how about trying to downgrade 1) vscode (1.46 or 1.47?) and 2) vscode-go (0.15.2 maybe) and to narrow down the issue?

I can try that later today or tomorrow.

Strange, yeah interestingly the extension worked for me initially without any env/path changes only after the error wouldn't go away did I follow the instructions I linked before which luckily resolved my issue

The only environment configuration I'm missing is explicitly setting $GOROOT. I've always relied on the fallback/default value of the Go install dir.

@dylan-bourque you shouldn't need to set $GOROOT. Actually, that's not recommended.

That was my understanding as well, but I noticed that it's included in the link that @CanRau posted.

Yes I've set it as shown and it resolved all problems 🤷🏻‍♂️

Why's it not recommended? 🤔

@CanRau Of course that's because the extension is also checking GOROOT/bin in addition to PATH etc. But what @dylan-bourque is getting at is about why the go extension isn't seeing the process.env['PATH'] it should see. I suspect a race between go extension's initialization and environment variable setup for extension host. Can we focus on the issue?

Re: why setting GOROOT is not recommended - if your GOROOT doesn't match what the go command thinks it should be, that can lead to other various issues. So, except a few cases where a different GOROOT is necessary, it's better to let the go command figure it out.

FYI just encountered another issue that talks about PATH issue on Mac that started recently
https://github.com/microsoft/vscode/issues/107169
https://github.com/microsoft/vscode/issues/106537 (suggests a 1.49.x regression)

cc @joaomoreno

Is there any message in the DevTools like this?

Unable to resolve shell environment in a reasonable time

I don't know if there was some specific change related to this, but I'm no longer seeing this behavior after updating VS Code to v1.50.0 and running the Go: Install/Update Tools command from the Go extension.

I'm getting this error, v1.50.1 hasn't fixed it. I'm seeing Unable to resolve shell environment in a reasonable time in my devtools.

Same here, usually I have to restart VSCode, second start works as expected 🤷‍♂️

Running Developer: reload window fixed it for me. Seems they reduced the timeout for loading the environment from 10s to 3s.

Uh good alternative, more work with multiple windows open tho 😅

@beamery-tomht interestingly since yesterday quiting&re-opening VSCode won't work anymore, luckily your Developer: reload window trick works, even though I have to do it for every single window failing 😅 better than "not being able to work" I guess 🤷‍♂️

No worries @CanRau , I stole the idea from the depths of another github issue thread and have to do the same for all of my windows. Luckily not all of them need the full environment!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

curtw picture curtw  ·  3Comments

shanalikhan picture shanalikhan  ·  3Comments

omidgolparvar picture omidgolparvar  ·  3Comments

VitorLuizC picture VitorLuizC  ·  3Comments

mrkiley picture mrkiley  ·  3Comments