golang/go · error
error loading go %s module graph: %w
Error message
error loading go %s module graph: %w
What it means
Thrown by checkTidyCompatibility (load.go:2100) when rs.Graph(ld, ctx) fails while building the module graph for an older Go compat version. During 'go mod tidy', the loader verifies reproducibility with prior Go versions; if it cannot even load the graph for the compat version, it wraps the underlying graph error with the compat version string and suggests fixes (printed to stderr). The %w preserves the original error for unwrapping.
Source
Thrown at src/cmd/go/internal/modload/load.go:2100
eFlag = " -e"
}
fmt.Fprintf(os.Stderr, "To upgrade to the versions selected by go %s%s:\n\tgo mod tidy%s -go=%s && go mod tidy%s -go=%s%s\n", compatVersion, eDesc, eFlag, compatVersion, eFlag, goVersion, compatFlag)
} else if suggestEFlag {
// If some packages are missing but no package is upgraded, then we
// shouldn't suggest upgrading to the Go 1.16 versions explicitly — that
// wouldn't actually fix anything for Go 1.16 users, and *would* break
// something for Go 1.17 users.
fmt.Fprintf(os.Stderr, "To proceed despite packages unresolved in go %s:\n\tgo mod tidy -e%s%s\n", compatVersion, goFlag, compatFlag)
}
fmt.Fprintf(os.Stderr, "If reproducibility with go %s is not needed:\n\tgo mod tidy%s -compat=%s\n", compatVersion, goFlag, goVersion)
fmt.Fprintf(os.Stderr, "For information about 'go mod tidy' compatibility, see:\n\thttps://go.dev/ref/mod#graph-pruning\n")
}
mg, err := rs.Graph(ld, ctx)
if err != nil {
pld.error(fmt.Errorf("error loading go %s module graph: %w", compatVersion, err))
pld.switchIfErrors(ctx)
suggestFixes()
pld.exitIfErrors(ctx)
return
}
// Re-resolve packages in parallel.
//
// We re-resolve each package — rather than just checking versions — to ensure
// that we have fetched module source code (and, importantly, checksums for
// that source code) for all modules that are necessary to ensure that imports
// are unambiguous. That also produces clearer diagnostics, since we can say
// exactly what happened to the package if it became ambiguous or disappeared
// entirely.
//
// We re-resolve the packages in parallel because this process involves disk
// I/O to check for package sources, and because the process of checking for
// ambiguous imports may require us to download additional modules that areView on GitHub (pinned to b6b368adc5)
Solutions
- Check the wrapped error (the %w part) for the root cause — often a network or checksum issue.
- Set GOPROXY correctly or verify module availability in your proxy/cache.
- Use 'go mod tidy -compat=X' explicitly to target a specific compat version, or '-e' to proceed despite errors.
Example fix
# before — compat graph fails due to unreachable module go mod tidy # error loading go 1.22 module graph: ... # after — fix proxy or proceed with -e go mod tidy -e # or set GOPROXY and retry: GOPROXY=https://proxy.golang.org,direct go mod tidy
Defensive patterns
Strategy: try-catch
Try / catch
// When running go mod tidy, handle compat graph load failures.
err := runGoModTidy()
if err != nil && strings.Contains(err.Error(), "error loading go") && strings.Contains(err.Error(), "module graph") {
// Retry with -e to proceed despite compat issues, or adjust -compat.
runGoModTidyWithFlags("-e")
} Prevention
- Ensure GOPROXY is set to a reachable proxy (e.g. https://proxy.golang.org,direct).
- Keep go.sum consistent with go.mod to avoid checksum failures during graph loading.
- Use 'go mod tidy -compat=<version>' to control which compat version is checked.
When it happens
Trigger: Running 'go mod tidy' when the module graph cannot be loaded for the compat version (the Go version prior to the one in the go.mod 'go' directive). This happens if a required module is unreachable, has a bad go.mod, or fails checksum verification when loaded for the older compat version.
Common situations: Network or proxy issues fetching a module needed for the compat check. A transitive dependency whose go.mod is malformed. 'go mod tidy' after changing the 'go' directive version, where the older graph references unavailable modules.
Related errors
- verifying %s: %v
- %s %s %s => %s%s: error finding sum for %s: %v
- %s: %w
- %s loaded from %v, but go %s would fail to locate it in %s
- bad checksum
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/0d910f9b326ba1d8.
Report an issue: GitHub.