Need Help: gopls and VSCode Setup with the Go Project - Nested Module Error

9,569 views
Skip to first unread message

arthurwil...@gmail.com

unread,
Apr 18, 2023, 1:07:44 AM4/18/23
to golang-nuts
Hey Golang-Nuts folks,

So I cloned the Go project from GitHub (github.com/golang/go) and tried to open it in Visual Studio Code with the Go extension. But I'm running into some pesky errors from gopls, and it's messing with the module detection.

When I open the root of the repo, I get this error message:

"Error loading workspace: gopls was not able to find modules in your workspace. When outside of GOPATH, gopls needs to know which modules you are working on. You can fix this by opening your workspace to a folder inside a Go module, or by using a go.work file to specify multiple modules. See the documentation for more information on setting up your workspace: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md."

However, when I open the 'src' directory in VSCode and make that the VSCode workspace root, I get a different gopls error:

"Error loading workspace: You have opened a nested module. To work on multiple modules at once, please use a go.work file. See https://github.com/golang/tools/blob/master/gopls/doc/workspace.md for more information on using workspaces."

Is there some other setup I need to do to make the Go project work with gopls? Any tips, tricks, or advice you can share would be super helpful.

Thanks in advance for any help!



Robert Findley

unread,
Apr 19, 2023, 12:50:55 AM4/19/23
to golang-nuts
Hi,

Yes, there are some gotchas involved with setting up VS Code with the Go project. The most common fix is to make sure that the go command resolved from PATH is the go command built via src/make.bash. There are some more details at https://github.com/golang/tools/blob/master/gopls/doc/advanced.md#working-on-the-go-source-distribution.

Hope that helps!
- Rob
Reply all
Reply to author
Forward
0 new messages