Go "missing go.sum entry for module" - Fix in CI
A build under the default -mod=readonly needs a module whose checksum is not recorded in go.sum. Go will not silently add it, so it stops.
What this error means
A build or test fails with missing go.sum entry for module providing package X; to add it: go mod download X. It usually means go.sum was not committed after a dependency change, or only a partial tidy was run.
missing go.sum entry for module providing package github.com/pkg/errors
(imported by example.com/app); to add it:
go mod download github.com/pkg/errorsCommon causes
go.sum not updated after a new import
A package was imported or a dependency bumped without running go mod tidy, so its checksum was never written to go.sum.
Partial commit of module files
go.mod was committed but go.sum was left out (or vice versa), leaving the checksum file incomplete.
How to fix it
Tidy and commit go.sum
- Run go mod tidy to reconcile go.mod and go.sum with the real import graph.
- Commit both files together so the readonly build has every checksum it needs.
go mod tidy
git add go.mod go.sum
git commit -m "go mod tidy"Guard tidiness in CI
- Run go mod tidy in the pipeline.
- Fail if it changes go.mod or go.sum, flagging an uncommitted update.
go mod tidy
git diff --exit-code go.mod go.sumHow to prevent it
- Run
go mod tidyafter every import or dependency change. - Always stage go.mod and go.sum together.
- Add a
git diff --exit-code go.mod go.sumguard to CI.