Go "updates to go.mod needed, disabled by -mod=mod" - Fix in CI
CI builds default to a mode that forbids rewriting go.mod. When the module graph needs a change the committed file lacks, Go refuses instead of editing it silently.
What this error means
A build or test stops with updates to go.mod needed, disabled by -mod=readonly. The same commands often pass locally where Go quietly edits go.mod, hiding the drift until CI enforces it.
go
go: updates to go.mod needed, disabled by -mod=readonly
to update it:
go mod tidyCommon causes
go.mod missing a required directive
An added import or bumped dependency needs a require or indirect line that was never written.
Local builds masked the drift
Local go commands auto-edit go.mod, so the gap never surfaced until readonly CI ran.
How to fix it
Tidy locally and commit
- Reconcile go.mod and go.sum with the real import graph using go mod tidy.
- Commit both files so the readonly build has everything it needs.
Terminal
go mod tidy
git add go.mod go.sumReproduce readonly locally
- Build with -mod=readonly to match CI behavior before pushing.
Terminal
go build -mod=readonly ./...How to prevent it
- Run
go mod tidyafter every dependency change and commit it. - Keep CI on
-mod=readonlyso drift fails fast. - Add a
git diff --exit-code go.mod go.sumguard.
Related guides
Go GOFLAGS=-mod=readonly conflict - Fix in CIFix Go GOFLAGS=-mod=readonly conflicting with a command that needs -mod=mod in CI - readonly blocks the go.mo…
Go "missing go.sum entry; to add it run go mod download" - Fix in CIFix Go "missing go.sum entry for module; to add it, run go mod download" in CI - go.sum lacks a checksum the…
Go "error loading module requirements" - Fix in CIFix Go "error loading module requirements" in CI - Go could not resolve the full module graph, often a bad re…