Go "no required module provides package" - Fix in CI
Go found an import in your code but no module in go.mod provides it. Without a require directive it cannot resolve where the package comes from.
What this error means
A build fails with no required module provides package X; to add it: go get X. It means an import was added without recording the providing module, or the path is misspelled.
app/main.go:6:2: no required module provides package github.com/spf13/cobra;
to add it:
go get github.com/spf13/cobraCommon causes
Import added without a require
New code imports a package but go get / go mod tidy was never run to add the providing module.
Misspelled import path
The import path is wrong, so no real module matches and Go reports it as unprovided.
How to fix it
Add the providing module
- Run go get for the package, or go mod tidy to resolve every import at once.
- Commit go.mod and go.sum.
go mod tidy
git add go.mod go.sumVerify the import path
- Confirm the path matches the real module path on its host and fix any typo.
go build ./...How to prevent it
- Run
go mod tidyafter adding any import. - Copy import paths from package docs to avoid typos.
- Add a tidiness guard so missing requires fail CI early.