Go "inconsistent vendoring" - Fix vendor/ Drift in CI
Go builds with -mod=vendor when a vendor/ directory exists, and it cross-checks vendor/modules.txt against go.mod. When they disagree, Go refuses to build with inconsistent vendoring rather than silently using stale code.
What this error means
A build fails with inconsistent vendoring in <dir>: listing modules that are in go.mod but not vendor/modules.txt (or vice versa), and a hint to run go mod vendor. It appears after editing go.mod without re-vendoring.
go: inconsistent vendoring in /home/runner/work/app:
github.com/example/lib@v1.4.0: is explicitly required in go.mod,
but not marked as explicit in vendor/modules.txt
To ignore the vendor directory, use -mod=mod or -mod=readonly.
To sync the vendor directory, run:
go mod vendorCommon causes
vendor/ not regenerated after a go.mod change
A dependency was added, removed, or bumped in go.mod, but go mod vendor was not re-run, so vendor/modules.txt no longer matches.
Partial commit of the vendor directory
A .gitignore rule or a partial commit left vendor/ out of sync with go.mod in the repository.
How to fix it
Regenerate and commit vendor/
Rebuild the vendor tree from the current module graph and commit the whole directory.
go mod tidy
go mod vendor
git add go.mod go.sum vendor/
git commit -m "Re-vendor dependencies"Or stop vendoring in CI
If you do not need a committed vendor tree, build against the module cache instead.
go build -mod=mod ./...
# or remove vendor/ entirely and rely on the proxy + cacheGuard vendor consistency in CI
go mod vendor
git diff --exit-code vendor/modules.txtHow to prevent it
- Run
go mod vendorafter everygo.modchange and commit all ofvendor/. - Decide between vendoring and module-cache builds, and apply it consistently.
- Add a
git diff --exit-code vendor/check to CI.