Go refuses a module version lookup because a vendor folder exists
Fix it fast
Most common cause, 1 of 2A go list -m query with @version runs inside a vendored project
Run the lookup with -mod=mod, which tells the go command to ignore the vendor directory for that one call.
go list -mod=mod -m example.com/some/module@latest
go list -mod=mod -m -u all
# for a script or tool that runs go list itself
GOFLAGS=-mod=mod ./scripts/check-updates.sh
# after changing a version
go mod tidy
go mod vendorShort answer
go: cannot query module due to -mod=vendor appears when go.mod says go 1.14 or later and a vendor directory exists. Go then defaults to -mod=vendor and refuses version queries such as go list -m example.com/m@latest. Add -mod=mod to that command, set GOFLAGS=-mod=mod for the tool, or delete an unwanted vendor folder. Applies to Go 1.26-1.27.
Which cause do you have?
Check whether the vendor folder is part of the repository or just lying around. Tracked files mean the project vendors on purpose; an empty result means the folder is a leftover.
git ls-files vendor | head -5Then find the line you see in this list and open its fix:
- 1A go list -m query with @version runs inside a vendored project
vendor/ is committed, and the failing command names a module with @latest, @v1.2.3 or another version query, typed by you or run by an update script - 2An old or copied vendor folder switches vendoring on by accident
git ls-files vendor prints nothing, or the team does not vendor dependencies and nobody remembers creating the folder
What does the error look like?
go: cannot query module due to -mod=vendor(Go version in go.mod is at least 1.14 and vendor directory exists.)
Cause 1 of 2
A go list -m query with @version runs inside a vendored project
You seevendor/ is committed, and the failing command names a module with @latest, @v1.2.3 or another version query, typed by you or run by an update script
Check
cannot query module due to -mod=vendor is Go protecting the vendor folder. With go 1.14 or higher in go.mod and a vendor directory present, the go command behaves as if -mod=vendor were passed, and in that mode it may not use the network or the module cache. Resolving @latest or any other version query needs both, so the query is refused. The related flags -u and -versions stop even earlier with a different message, can't determine available upgrades using the vendor directory, and take the same fix.
go list -m example.com/some/module@latestFix
Run the lookup with -mod=mod, which tells the go command to ignore the vendor directory for that one call. For a tool you cannot pass flags to, put the flag in GOFLAGS for that tool only. Re-vendor after any version change so vendor/modules.txt matches go.mod.
go list -mod=mod -m example.com/some/module@latest
go list -mod=mod -m -u all
# for a script or tool that runs go list itself
GOFLAGS=-mod=mod ./scripts/check-updates.sh
# after changing a version
go mod tidy
go mod vendorVerify
The query prints the module path and the version it resolved to, and go build still works from the vendor folder.
go build ./... && go list -mod=mod -m example.com/some/module@latestConfirmed by go.dev
Cause 2 of 2
An old or copied vendor folder switches vendoring on by accident
You seegit ls-files vendor prints nothing, or the team does not vendor dependencies and nobody remembers creating the folder
Check
Go never asks whether you meant to vendor. If a directory named vendor sits in the main module's root and go.mod declares 1.14 or later, the go command starts using it automatically. A folder left by an old build script, an archive or a copy from another project turns on vendor mode and blocks version lookups.
ls vendor/modules.txt && git status --short vendor | headFix
Remove the folder and let the module cache serve dependencies again. Run go mod tidy afterwards so go.mod and go.sum are complete without it.
rm -rf vendor
go mod tidyVerify
The version lookup now works without extra flags, and builds read from the module cache.
go list -m example.com/some/module@latestConfirmed by go.dev
How do I stop it coming back?
- Decide once whether the repository vendors. If it does, commit vendor/ and add a CI step that runs go mod vendor and fails on a diff.
- Where the team does not vendor, let CI reject any commit that brings a vendor folder back, for example with test ! -d vendor.
- In update scripts, write -mod=mod into every go list -m call that uses @version, -u or -versions, instead of relying on each developer's environment.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.