Skip to content
Latchkey

go mod vendor: Usage, Options & Common CI Errors

Vendor dependencies into the repo for offline builds.

go mod vendor writes a vendor/ directory containing the source of all dependencies needed to build and test the module. When vendor/ is present, the go command builds from it by default.

What it does

Copies dependency packages into vendor/ and writes vendor/modules.txt describing them. With a vendor/ directory the default build mode becomes -mod=vendor, so builds use it and skip the network.

Common usage

Terminal
go mod vendor                     # create/refresh vendor/
go build -mod=vendor ./...        # force building from vendor/
go test -mod=mod ./...            # ignore vendor/, use the cache

Common CI error: inconsistent vendoring

go build fails with "inconsistent vendoring" because go.mod was changed but vendor/ (and vendor/modules.txt) was not regenerated. Fix: run go mod vendor and commit the updated vendor/ directory alongside go.mod, so they stay in sync.

Options

FlagEffect
-mod=vendorBuild from vendor/
-mod=modIgnore vendor/, use cache
-vList vendored packages

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →