Skip to content
Latchkey

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 output
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 vendor

Common 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.

Terminal
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.

Terminal
go build -mod=mod ./...
# or remove vendor/ entirely and rely on the proxy + cache

Guard vendor consistency in CI

.github/workflows/ci.yml
go mod vendor
git diff --exit-code vendor/modules.txt

How to prevent it

  • Run go mod vendor after every go.mod change and commit all of vendor/.
  • Decide between vendoring and module-cache builds, and apply it consistently.
  • Add a git diff --exit-code vendor/ check to CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →