golang compile simple app module not found (GOPATH?)

You’ll need to use a replace directive to point to the local path to the package. Otherwise Go tries to find it where the actual path is — at example.com/greeting. In the page you link to, this is mentioned:

For production use, you’d publish your modules on a server, either inside your company or on the internet, and the Go command will download them from there. For now, you need to adapt the caller’s module so it can find the greetings code on your local file system.

To do that, make a small change to hello module’s go.mod file.

In the hello directory, open the go.mod file, change it so that it looks like the following, and save the file.

module hello

go 1.14

replace example.com/greetings => ../greetings

In fact, since you’re using modules (as you should with go 1.15!) I would recommend not setting at all. It’s not needed, and just adds confusion in “module mode”.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top