5

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/redis.v5@v5.2.9: 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.

Bee
  • 195
  • 1
  • 3
  • 12

3 Answers3

7

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
. . .
rustyx
  • 80,671
  • 25
  • 200
  • 267
  • Thank you, I was unable to find this information elsewhere. In my case I upgraded Go from 1.10 to 1.16 and saw this error with an otherwise synced vendor folder because the original modules.txt did not have `## explicit`. Adding those lines solved the problem. – Matt Mc Jun 03 '22 at 18:03
4

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.

Fahima Mokhtari
  • 1,691
  • 2
  • 16
  • 30
0

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