Skip to content
Latchkey

Go test "no required module provides package" - Fix in CI

A test file imports a package - often a test-only helper like testify - that no module in go.mod provides. go test fails the same way a build would, before any test runs.

What this error means

go test fails with no required module provides package X; to add it: go get X, naming a package used only in _test.go files. It means a test dependency was imported without being added to go.mod.

go
app/store_test.go:8:2: no required module provides package github.com/stretchr/testify/assert;
	to add it:
	go get github.com/stretchr/testify/assert

Common causes

Test-only import not required

A package used solely in tests was imported but go mod tidy never added it to go.mod.

tidy run without test imports considered

A partial tidy or an older Go did not record a test-only dependency.

How to fix it

Add the test dependency and tidy

  1. Run go get for the test package or go mod tidy to capture test imports.
  2. Commit go.mod and go.sum.
Terminal
go get github.com/stretchr/testify@latest
go mod tidy

Guard tidiness in CI

  1. Run go mod tidy and fail if go.mod or go.sum changes, catching missing test deps.
.github/workflows/ci.yml
go mod tidy
git diff --exit-code go.mod go.sum

How to prevent it

  • Run go mod tidy after adding any test import.
  • Stage go.mod and go.sum together.
  • Add a tidiness guard to CI so missing test deps fail early.

Frequently asked questions

What causes "test: no module provides package"?
A package used solely in tests was imported but go mod tidy never added it to go.mod.
How do I fix test: no module provides package?
Add the test dependency and tidy

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card