"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

go/packages.Load: no packages found

2019-10-22

Categories: Programming

I have a mono-repo, structure like this:

1repo
2├── service1
3├── service2
4├── go.mod

I often open the root folder from the command line by using code .. After that I open a file in service1, and cannot go to definition. Here’s the logs from gopls:

1[Info  - 5:49:28 AM] 2019/10/22 05:49:28 20.675656ms for GOROOT=/usr/local/Cellar/go/1.13/libexec GOPATH=/Users/quanta/go GO111MODULE=auto PWD=/Users/quanta/go/src/github.com/owner/repo go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=false" "-deps=true" "-find=false" "--" "/Users/quanta/go/src/github.com/owner/repo/a/b/c", stderr: <<go: directory a/b/c is outside main module
2>>
3
4[Error - 5:49:32 AM] Request textDocument/definition failed.
5  Message: go/packages.Load: no packages found for /Users/quanta/go/src/github.com/owner/repo/a/b/c/file.go
6  Code: 0 

So, gopls only works if we open vscode at the module root (service1, service2 in this case). If you open vscode at the project root, you have to use File -> Add Folder to Workspace to create a workspace with multiple folders.

Tags: go gopls

Edit on GitHub

Related Posts: