skip to Main Content

I’m getting this inconsistent vendoring error and I’m a total Go newbie. Can anyone explain to me how go.mod interacts with vendor/modules.txt? I found this question helpful, and now I’m wondering if I should even have a vendor directory. Would that be created by running go mod vendor? I inherited this project and it already has the vendor directory in git.

Here’s the relevant part of my go.mod file –

module mymodule

go 1.17

require (
        gopkg.in/redis.v5 v5.2.9
)

And then the related error message:

go: inconsistent vendoring
gopkg.in/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

In vendor/modules.txt I have:

#gopkg.in/redis.v5 v5.2.9
gopkg.in/redis.v5
gopkg.in/redis.v5/internal
gopkg.in/redis.v5/internal/consistenthash
gopkg.in/redis.v5/internal/hashtag
gopkg.in/redis.v5/internal/pool
gopkg.in/redis.v5/internal/proto

For what it’s worth I’m getting this error for every dependency in my go.mod file, I just included the one about redis.

3

Answers


  1. go.mod and vendor/modules.txt (if present) must be in sync.

    Whenever go.mod changes and there is a vendor directory, go mod vendor needs to be run to update the contents of the vendor directory.

    All direct dependencies (not marked // implicit in go.mod) are "explicit" and marked accordingly in vendor/modules.txt starting from Go 1.14.

    After running go mod vendor notice the new line ## explicit added after the package reference:

    #gopkg.in/redis.v5 v5.2.9
    ## explicit
    . . .
    
    Login or Signup to reply.
  2. Just to add to @rustyx’s answer, in order to fix this error, I deleted the vendor folder and then I ran again go mod vendor, and the error disappeared.

    Login or Signup to reply.
  3. For me updating the version solved the issue. I was running go1.16 and I updated to go1.18.2. Before the update I tried go mod vendor and also updating the modules.txt didn’t work then, I started ignoring the vendor directory by running
    go build -mod=mod to build the application or go run -mod=mod main.go to run the main.go file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search