Go: missing go.sum entry for module providing package
Read-only module mode refuses to invent checksums. Run go mod tidy locally, download in CI and keep vendor trees and workspaces consistent.

Introduction & Quick Summary
A clean CI checkout fails before compiling anything:
missing go.sum entry for module providing package github.com/stretchr/testify/assert
(imported by example.com/shop/internal/cart); to add:
go get example.com/shop/internal/cartQuick answer: the module graph needs a checksum for a dependency that go.sum does not record, and the build is in read-only module mode. Add the entry with go mod tidy, or the narrower command Go prints.
go mod tidy # reconcile go.mod and go.sum with the imports
go build ./...Since Go 1.16 the default is -mod=readonly: the toolchain will not edit go.mod or go.sum during a build. A developer who runs go get locally updates both files, while CI builds from the same commit and refuses to improvise. That asymmetry explains why the failure usually appears only in CI or on a colleague's machine.
Two message forms point at different files:
missing go.sum entry for module providing package X— an import needs a module whose content hash is absent.missing go.sum entry for go.mod file; to add it: go mod download X— the module's owngo.modis not recorded, usually after areplaceor an indirect dependency change.
Both are fixed by the same command, but the printed hint tells you which module to fetch when a full go mod tidy is not appropriate.
Core Mechanics, Signatures & Reproducible Setup
Reproduce in a scratch module:
mkdir gosum && cd gosum
go mod init example.com/gosum
cat > main.go <<'GO'
package main
import (
"fmt"
"github.com/google/uuid"
)
func main() { fmt.Println(uuid.NewString()) }
GO
GOFLAGS=-mod=readonly go build ./...The build fails with the message above because go.mod does not list the module and go.sum has no hashes. go mod tidy adds both. go.sum holds two lines per module version: one hash of the module archive and one of its go.mod. The h1: hash is a SHA-256 over a canonical file tree, which is why a changed zip changes the hash even when the version string is identical.
| File | Purpose | Who edits it |
|---|---|---|
go.mod | module path, Go version, direct and indirect requirements | go get, go mod tidy |
go.sum | checksums for verification | the toolchain, never by hand |
go.work | multi-module workspace | go work init and go work use |
vendor/modules.txt | vendored dependency list | go mod vendor |
GOSUMDB | checksum database to consult | go env -w |
Key Comparison Table
| Command | Edits go.mod | Edits go.sum | Network | Use when |
|---|---|---|---|---|
go mod tidy | yes, prunes and adds | yes | yes | after changing imports |
go mod download X | no | yes, for X | yes | one missing module in CI |
go get X@v1.2.3 | yes | yes | yes | adding or upgrading a dependency |
go build (default) | no | no | cache only | normal builds |
go build -mod=mod | yes | yes | yes | local one-off, never CI |
go mod vendor | no | no | cache | deployments that ship vendor |
Which mode the build uses:
| Condition | Effective mode | Behaviour with a missing entry |
|---|---|---|
vendor/ present, Go 1.14 or later | -mod=vendor | uses modules.txt, reports inconsistent vendoring |
GOFLAGS=-mod=readonly | read-only | fails with the go.sum message |
GOFLAGS=-mod=mod | writable | silently updates go.sum |
go.work present | workspace mode | reads go.work.sum for verification |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Tidy locally, then commit both files
go mod tidy
git diff --stat go.mod go.sum
go mod verifygo mod tidy also removes entries that are no longer needed, which is why a tidy-only commit can shrink go.sum by hundreds of lines. Review that diff: an accidental removal of a build-tag-only dependency breaks another platform. Run go mod tidy with the Go version named in go.mod to avoid the toolchain rewriting the go directive.
Two hashes per module are normal, not duplication. The h1: line for the module archive covers the zip contents, and the /go.mod line covers the module's declaration. A dependency that appears only through a go.mod requirement, never through an import, still needs the /go.mod hash, which is why go mod tidy can add entries for modules your code never imports directly.
2. CI cannot write files
When the pipeline mounts the workspace read-only or runs as a user without write access, go mod tidy fails with a permission error rather than fixing anything. The correct sequence for CI is download first, build with the default mode:
go mod download
go build ./...If the repository is genuinely missing an entry, the pipeline needs a commit, not a flag. Setting GOFLAGS=-mod=mod in CI hides the missing file and produces a build from an unreviewed module version. A cache warm-up step that runs go mod download before the build also shortens later stages, because every stage that runs it reads from the same module cache.
3. Vendored builds
go mod vendor
git add vendor/modules.txt vendor/
git commit -m "vendor: refresh dependencies"A repository with a vendor directory ignores go.sum for content verification and trusts modules.txt. When the import graph changes without re-running go mod vendor, the build reports inconsistent vendoring instead of the go.sum message. Copying a vendor directory from another checkout without its modules.txt produces the same failure and a much longer investigation.
4. Workspaces and multi-module repositories
go work init ./service ./shared
go work use ./tools
go work syncIn workspace mode the toolchain verifies modules against go.work.sum, not each module's go.sum. A CI job that builds inside a workspace and a Dockerfile that builds the module alone therefore see different checksum files. Either commit go.work.sum and build in workspace mode everywhere, or exclude the workspace in CI with GOWORK=off and let each module use its own go.sum.
5. Private modules and GOPRIVATE
go env -w GOPRIVATE=github.com/acme/*,git.acme.internal/*
go env -w GOFLAGS=-mod=readonlyGOPRIVATE tells the toolchain not to publish these paths to the public checksum database, and GONOSUMDB-era advice in older guides no longer applies. It does not skip go.sum: a private module still needs its hashes recorded, or the build fails with the message in this article. For a module served by a private proxy, set the order in GOPROXY, for example https://proxy.acme.internal,direct, so a miss falls back to the upstream VCS over SSH. Authentication for that fallback comes from the git credential helper, which is why the same build can work on a laptop and fail in a container without the helper installed.
6. Checksum mismatches are a different failure
verifying github.com/foo/bar@v1.4.2: checksum mismatch
downloaded: h1:AAAA...
go.sum: h1:BBBB...This is not a missing entry; it means the downloaded content does not match the recorded hash. Causes include a modified module proxy, a retracted version republished by a private mirror, or a hand-edited go.sum. Do not delete the line to proceed. Delete the module from the cache (go clean -modcache), retry, and if the mismatch persists treat it as a supply-chain signal. The hash tool computes SHA-256 over a file but not over a module zip tree, so compare the h1: value with the public checksum database instead.
Common Compilation/Runtime Mistakes & Version Gotchas
Deleting go.sum "to reset it". The next build re-resolves every version from the proxy, which can upgrade indirect dependencies and change behaviour. Tidy instead of deleting.
Ignoring the printed hint. to add: go get example.com/shop/internal/cart names the importing package, which is often not the module you expected to be missing. Reading it saves a round of guessing.
Running go get with no argument. It upgrades dependencies to their latest versions rather than adding the one missing entry, silently changing the build.
Committing a vendor directory without modules.txt. Go treats the vendor tree as unverifiable and refuses to build; the error names vendoring, not go.sum, which sends searches down the wrong path.
Adding go.sum to .gitignore. Every developer then resolves modules independently, and a dependency upgrade can reach production unreviewed. The file is meant to be committed.
Editing go.sum by hand. The format looks simple, but a hash computed over the wrong tree silently fails verification later, and a removed line reappears on the next tidy. Regenerate it with a command instead.
Version notes. Go 1.17 changed go.mod to list all transitive requirements explicitly, so an older module shows a much larger diff after the first tidy under a new toolchain. Go 1.21 made go mod tidy keep checksums for the previous Go version's requirements unless -compat says otherwise. Go 1.22 added toolchain lines that can trigger a download during build; pin GOTOOLCHAIN=local in CI when the exact compiler matters. Check environment values such as GOFLAGS and GOPROXY with the env formatter when local and CI results disagree.
Reference material: Go modules reference and Managing dependencies.
Official references
primary documentationThe Go documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Go work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Go guides
All Go guidesGo: x509 certificate signed by unknown authority
Go cannot build a chain to a trusted root: no CA bundle in the image, a private CA, or a missing intermediate. Install roots or set RootCAs.
Go: fatal error: concurrent map writes in goroutines
The runtime catches two writes to one map and stops the process. Guard access with a mutex, use sync.Map for caches, or give one owner.
Go: go.mod file not found in current directory
Go 1.16 and later build in module mode. Run commands inside the module root, create a go.mod with go mod init, or set GO111MODULE and GOWORK deliberately.
Go: import cycle not allowed
Go forbids cycles in the package import graph. Break them by extracting shared types, declaring interfaces where consumed, or inverting init registration.
More in Go
All Go guidesThe guides filed next to this one in Go, in library order.