Go — inconsistent vendoring error
Fix inconsistent vendoring by syncing the vendor directory with go.mod or disabling vendoring explicitly.
Symptoms
- inconsistent vendoring
- go: inconsistent vendoring of module X
- The build uses a vendor directory that no longer matches go.mod
- CI fails after a dependency update
Possible causes
- go.mod or go.sum changed without updating the vendor directory
- The vendor directory exists but is stale
- Build flags force vendor mode while dependencies changed
- A dependency was added without running go mod vendor
Diagnosis steps
Read what is inconsistent
go build ./... 2>&1 | head -20Interpretation
The message names the module and the mismatch, such as missing from vendor or present only in vendor.
Regenerate the vendor directory
go mod tidy && go mod vendorInterpretation
Tidying first resolves go.sum, and vendoring copies exactly what go.mod requires so the two agree.
Decide vendor or modules explicitly
go env GOFLAGS && ls vendor/modules.txtInterpretation
If vendoring is not intended, remove the directory and ensure the build does not force -mod=vendor.
Root cause
The build used the vendor directory while go.mod and go.sum described a different dependency set, so the vendored sources did not match what the build expected.
Fix
Run go mod vendor after any dependency change so vendor matches go.mod, or remove the vendor directory and let the module cache resolve dependencies, keeping the build mode explicit.
Verify the fix
Build and test again and confirm the inconsistency is gone, and confirm the vendored dependency versions match go.mod.
Symptom walkthrough
The build fails with inconsistent vendoring, naming a module that is missing from or extra in the vendor directory. The vendor directory is a snapshot of dependencies, so any change to go.mod or go.sum without regenerating it leaves the two out of sync. CI frequently fails this way after a dependency update that was not accompanied by a vendor regeneration.
Fix in practice
After any dependency change, run go mod tidy and then go mod vendor so the snapshot matches the module requirements. If the project does not intend to vendor, remove the directory and keep the build mode consistent so it does not force vendor mode.
Verification
Rebuild and run the tests and confirm the inconsistency is gone, then confirm the vendored module versions match those in go.mod. Agreement between the snapshot and the module file confirms the fix.
Diagnostic commands
Check the behavior with commands like these:
go build ./... 2>&1 | head -20
go mod tidy && go mod vendor
go env GOFLAGS && ls vendor/modules.txt