nvim-dap-go icon indicating copy to clipboard operation
nvim-dap-go copied to clipboard

Build Error: cannot find package

Open 9albi opened this issue 1 year ago • 1 comments

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

image

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.

9albi avatar Mar 10 '24 19:03 9albi

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.

leoluz avatar Mar 25 '24 01:03 leoluz

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.

stale[bot] avatar Sep 21 '24 09:09 stale[bot]