Build Error: cannot find package #72

Closed
opened 2024-03-10 22:22:34 +03:00 by 9albi · 2 comments
9albi commented 2024-03-10 22:22:34 +03:00 (Migrated from github.com)

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.

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](https://github.com/leoluz/nvim-dap-go/assets/127761370/7f8372f5-bd17-4a24-bfff-37728920b20a) 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](https://github.com/leoluz/nvim-dap-go/issues/16) but sadly nothing there helped. I hope I could find a solution here. Thank you for your time.
leoluz commented 2024-03-25 04:23:36 +03:00 (Migrated from github.com)

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.

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.
stale[bot] commented 2024-09-21 12:02:11 +03:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
NeonXP/nvim-dap-go#72
No description provided.