Go build: cannot find package, although GOPATH and modules are configured
Hello, colleagues! I'm new to Go and have been struggling with a problem for the second day. I wrote a simple program that uses an external package for working with JSON (e.g., `github.com/tidwall/gjson`). I installed Go 1.22 on Ubuntu, created a folder `~/go_projects/myapp`, and inside it — a file `main.go`.
Here is my code:
```go
package main
import (
"fmt"
"github.com/tidwall/gjson"
)
func main() {
json := `{"name": "Alice", "age": 30}`
value := gjson.Get(json, "name")
fmt.Println(value.String())
}
```
I ran `export GOPATH=$HOME/go` and `export PATH=$PATH:$GOPATH/bin`, then ran `go mod init myapp` in the project folder. After that I tried `go build`, but got the error:
```
build command-line-arguments: cannot find package "github.com/tidwall/gjson" in any of:
/
No answers yet.
Log in to leave an answer