others-how to solve 404 not found: go.mod has non problem when running golang module ?

Problem

When we create a golang module with dependencies as follows:

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 :

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 do this error happen? The dependencies are all correct, I promise!!!

Environment

  • go version go1.14

Reason

Our module have a depenency on fsnotify, but the specified version 1.4.9 can not be found in our go package repository.

Solution

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

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 indirect dependency?

Indirect dependency, is basically 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:

go mod graph 

Run the app again, No error messages ,It works!