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
go.mod
andvendor/modules.txt
(if present) must be in sync.Whenever
go.mod
changes and there is avendor
directory,go mod vendor
needs to be run to update the contents of thevendor
directory.All direct dependencies (not marked
// implicit
ingo.mod
) are "explicit" and marked accordingly invendor/modules.txt
starting from Go 1.14.After running
go mod vendor
notice the new line## explicit
added after the package reference:Just to add to @rustyx’s answer, in order to fix this error, I deleted the
vendor
folder and then I ran againgo mod vendor
, and the error disappeared.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