Build Error: cannot find package
Hello, I'm facing an issue getting the debugger to start.
Test Case
consider the following simple go project:
~/workspace/gotest/
├─ pkg/
│ ├─ file.go
├─ main.go
├─ go.mod
// file.go
package pkg
import "fmt"
func Foo() {
fmt.Println("foo")
}
// main.go
package main
import "testmodule/pkg"
func main() {
pkg.Foo()
}
When trying to debug main
The following error occurs:
Build Error: go build -o /home/bacteria/__debug_bin3602612132 -gcflags all=-N -l /home/bacteria/workspace/gotest/main.go
workspace/gotest/main.go:3:8: cannot find package "testmodule/pkg" in any of:
/usr/local/go/src/testmodule/pkg (from $GOROOT)
/home/bacteria/go/src/testmodule/pkg (from $GOPATH) (exit status 1)
The only workaround I've found is to move the project to $GOPATH/src.
~ echo $GOPATH
/home/bacteria/go
~ go env GO111MODULE
auto
I've tried using dlv manually and in vscode. Both seem to work fine. I've seen a similar Issue but sadly nothing there helped. I hope I could find a solution here.
Thank you for your time.
It seems that you have an issue with how you are declaring your go module. Make sure the name of your module match your import statement.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.