Go "error loading module requirements" - Fix in CI
Before building, Go loads the complete module requirement graph. If any required module cannot be read or resolved, the whole load fails with error loading module requirements.
What this error means
A command fails early with go: error loading module requirements followed by a deeper cause - a missing version, an unreachable host, or a malformed go.mod in a dependency. The build never reaches compilation.
go: error loading module requirements
go: github.com/foo/bar@v1.0.0: reading github.com/foo/bar/go.mod at revision v1.0.0: unknown revision v1.0.0Common causes
A transitive require cannot be resolved
A dependency-of-a-dependency points at a missing version or unreachable host, so the graph cannot be completed.
Malformed go.mod somewhere in the graph
A required module ships a go.mod Go cannot parse, breaking the requirement load.
How to fix it
Read the deeper error and fix the offender
- Look at the line after the summary for the real cause.
- Pin a valid version of the offending module, then tidy.
go mod tidy
go mod graph | grep foo/barTrace why a module is required
- Use go mod why and go mod graph to find what pulls in the broken requirement.
go mod why github.com/foo/barHow to prevent it
- Keep dependencies pinned to published, resolvable versions.
- Run
go mod tidyand verify the graph loads before pushing. - Cache the module cache so resolved requirements are reused.