Error "package XXX is not in GOROOT" when building Go project
Hi everyone! I just started learning Go and encountered a strange error. I created a simple project with this structure:\n\n```\nmyapp/\n├── main.go\n└── utils/\n └── helper.go\n```\n\nIn `main.go` I import my package:\n\n```go\npackage main\n\nimport "myapp/utils"\n\nfunc main() {\n utils.SayHello()\n}\n```\n\nAnd in `utils/helper.go`:\n\n```go\npackage utils\n\nimport "fmt"\n\nfunc SayHello() {\n fmt.Println("Hello from utils!")\n}\n```\n\nI try to build: `go build main.go` — and I get:\n\n```\nmain.go:3:8: package myapp/utils is not in GOROOT (/usr/local/go/src/myapp/utils)\n```\n\nGo version 1.21, installed via the official installer. The project is located in `~/projects/myapp`. I haven't configured the `GOPATH` variable. I tried running `go env -w GO111MODULE=off`, but then another error appears.
No answers yet.
Log in to leave an answer