I am trying to install the Go tools in Visual Studio Code and am getting the following error when installing gopls:
Tools environment: GOPATH=/Users/jal/go
Installing 1 tool at /Users/jal/go/bin in module mode.
gopls
Installing golang.org/x/tools/gopls@latest FAILED
{
"killed": false,
"code": 2,
"signal": null,
"cmd": "/opt/brew/bin/go install -v golang.org/x/tools/gopls@latest",
"stdout": "",
"stderr": "golang.org/x/tools/internal/fastwalk\n# golang.org/x/tools/internal/fastwalk\n../../go/pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found\n#include <dirent.h>\n ^~~~~~~~~~\n1 error generated.\n"
}
1 tools failed to install.
gopls: failed to install gopls(golang.org/x/tools/gopls@latest): Error: Command failed: /opt/brew/bin/go install -v golang.org/x/tools/gopls@latest
golang.org/x/tools/internal/fastwalk
# golang.org/x/tools/internal/fastwalk
../../go/pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk_darwin.go:11:10: fatal error: 'dirent.h' file not found
#include <dirent.h>
^~~~~~~~~~
1 error generated.
I know I have dirent.h
because I see results in my local Xcode SDKs when running find / -iregex ".*/dirent.h$" 2>/dev/null
.
I am following the steps here: https://learn.microsoft.com/en-us/azure/developer/go/configure-visual-studio-code
My setup is:
- Fresh install of go from Homebrew
- Fresh install of VSCode macOS from go.dev/doc/install
- Instal the Go plugin
- In the Command Palette, search for and select "Go: Install/Update tools" and select all tools in the dropdown
All tools are installed successfully except for gopls. I have installed go via Homebrew and have also installed gopls via Homebrew but am not sure how to configure VSCode to point to this alternative gopls path.
The issue seemed to be due to a misconfigured or corrupted Xcode and command line tools.
I uninstalled and re-installed the latest version of Xcode, as well as the Command Line Tools package (this one is especially important) from here https://developer.apple.com/download/all/.
I had to do this despite
xcode-select --install
telling me everything was installed correctly and up to date.Future issue discussion available here: https://github.com/golang/go/issues/56663