Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

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.

~6 min readGo
#go#modules#go-sum#ci
Bold white headline reading MISSING GO SUM with a Go module crate holding an amber empty checksum slot beside a cyan hash plate.

Introduction & Quick Summary

A clean CI checkout fails before compiling anything:

code
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/cart

Quick 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.

bash
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 own go.mod is not recorded, usually after a replace or 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:

bash
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.

FilePurposeWho edits it
go.modmodule path, Go version, direct and indirect requirementsgo get, go mod tidy
go.sumchecksums for verificationthe toolchain, never by hand
go.workmulti-module workspacego work init and go work use
vendor/modules.txtvendored dependency listgo mod vendor
GOSUMDBchecksum database to consultgo env -w

Key Comparison Table

CommandEdits go.modEdits go.sumNetworkUse when
go mod tidyyes, prunes and addsyesyesafter changing imports
go mod download Xnoyes, for Xyesone missing module in CI
go get X@v1.2.3yesyesyesadding or upgrading a dependency
go build (default)nonocache onlynormal builds
go build -mod=modyesyesyeslocal one-off, never CI
go mod vendornonocachedeployments that ship vendor

Which mode the build uses:

ConditionEffective modeBehaviour with a missing entry
vendor/ present, Go 1.14 or later-mod=vendoruses modules.txt, reports inconsistent vendoring
GOFLAGS=-mod=readonlyread-onlyfails with the go.sum message
GOFLAGS=-mod=modwritablesilently updates go.sum
go.work presentworkspace modereads go.work.sum for verification

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Tidy locally, then commit both files

bash
go mod tidy git diff --stat go.mod go.sum go mod verify

go 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:

bash
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

bash
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

bash
go work init ./service ./shared go work use ./tools go work sync

In 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

bash
go env -w GOPRIVATE=github.com/acme/*,git.acme.internal/* go env -w GOFLAGS=-mod=readonly

GOPRIVATE 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

code
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 documentation

The Go documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Go work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Go guides

More in Go

All Go guides

The guides filed next to this one in Go, in library order.