Skip to content

How to resolve 404 not found: go.mod has non problem when running golang module

Problem

When we create a Go module with dependencies as follows:

go.mod
go 1.14
require (
k8s.io/apimachinery v0.17.2
k8s.io/client-go v0.17.2
sigs.k8s.io/controller-runtime v0.5.0
)

When we run the module, we get this error:

Terminal window
go get: upgrading gopkg.in/[email protected]: gopkg.in/[email protected]: reading https://goproxy.io/gopkg.in/fsnotify.v1/@v/v1.4.9.info: 404 Not Found
server response: not found: go.mod has non-....v1 module path "github.com/fsnotify/fsnotify" at revision v1.4.9

The core error is: 404 Not Found, server response: not found: go.mod has non-…v1 module path “github.com/fsnotify/fsnotify” at revision v1.4.9

Why does this error occur? The dependencies are all correct, I promise!

Environment

  • Go version: go1.14

Reason

Our module has a dependency on fsnotify, but the specified version 1.4.9 cannot be found in our Go package repository.

Solution

We should specify an available version (1.4.7) in the Go package repository by using an indirect dependency as follows:

go.mod
go 1.14
require (
k8s.io/apimachinery v0.17.2
k8s.io/client-go v0.17.2
sigs.k8s.io/controller-runtime v0.5.0
gopkg.in/fsnotify.v1 v1.4.7 // indirect
)

What is an indirect dependency?

Indirect dependency is basically a dependency that wasn’t listed in go.mod of your direct dependency but is still required by it. — by Grigoriy Mikhalkin and Flimzy

You can visualize your dependency graph as follows:

Terminal window
go mod graph

Run the app again, and there should be no error messages. It works!

Summary

In this post, we explored how to resolve the 404 Not Found error when running a Go module. The error occurs when the specified version of a dependency is not available in the Go package repository. By using an indirect dependency, we can specify an available version and resolve the issue. Always ensure that the versions of your dependencies are correctly specified and available in the repository to avoid such errors.

Final Words + More Resources

My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!