golang/go · error
requested Go version %s cannot load module graph (requires G
Error message
requested Go version %s cannot load module graph (requires Go >= %s)
What it means
Thrown by modload.LoadModGraph when a caller passes an explicit goVersion that is older than the 'go' directive already selected for the main module's go.mod (when that directive is >= GoStrictVersion). The Go version governs module-graph pruning: a too-old version cannot reproduce the pruned graph the module declared. It is a hard precondition check before rs.Graph is ever consulted.
Source
Thrown at src/cmd/go/internal/modload/buildlist.go:568
// without loading any packages.
//
// If the goVersion string is non-empty, the returned graph is the graph
// as interpreted by the given Go version (instead of the version indicated
// in the go.mod file).
//
// Modules are loaded automatically (and lazily) in LoadPackages:
// LoadModGraph need only be called if LoadPackages is not,
// typically in commands that care about modules but no particular package.
func LoadModGraph(ld *Loader, ctx context.Context, goVersion string) (*ModuleGraph, error) {
rs, err := loadModFile(ld, ctx, nil)
if err != nil {
return nil, err
}
if goVersion != "" {
v, _ := rs.rootSelected(ld, "go")
if gover.Compare(v, gover.GoStrictVersion) >= 0 && gover.Compare(goVersion, v) < 0 {
return nil, fmt.Errorf("requested Go version %s cannot load module graph (requires Go >= %s)", goVersion, v)
}
pruning := pruningForGoVersion(goVersion)
if pruning == unpruned && rs.pruning != unpruned {
// Use newRequirements instead of convertDepth because convertDepth
// also updates roots; here, we want to report the unmodified roots
// even though they may seem inconsistent.
rs = newRequirements(ld, unpruned, rs.rootModules, rs.direct)
}
return rs.Graph(ld, ctx)
}
rs, mg, err := expandGraph(ld, ctx, rs)
if err != nil {
return nil, err
}
ld.requirements = rsView on GitHub (pinned to b6b368adc5)
Solutions
- Upgrade the active Go toolchain to at least the version in the go.mod 'go' directive (e.g. go get toolchain@go1.22.x or install a newer Go).
- If you intentionally need an older toolchain, lower the go.mod 'go' directive to match (edit go.mod 'go 1.X' line), accepting you lose pruning guarantees.
- Drop the explicit goVersion argument / -go flag so LoadModGraph defaults to the module's declared version.
- Run 'go env GOTOOLCHAIN' and ensure it is 'auto' or a version >= the required one, not a pinned-older value.
Example fix
// before $ GOTOOLCHAIN=go1.19 go mod graph // module go.mod says 'go 1.22' // error: requested Go version go1.19 cannot load module graph (requires Go >= 1.22) // after $ GOTOOLCHAIN=auto go mod graph // let it pick >= 1.22 // or edit go.mod: go 1.19 // if you accept the downgrade
Defensive patterns
Strategy: validation
Validate before calling
// Before calling LoadModGraph, ensure goVersion is >= the go.mod directive.
if goVersion != "" {
if v, ok := rs.rootSelected(ld, "go"); ok {
if gover.Compare(v, gover.GoStrictVersion) >= 0 && gover.Compare(goVersion, v) < 0 {
return nil, fmt.Errorf("refusing to call LoadModGraph: %s < required %s", goVersion, v)
}
}
}
return LoadModGraph(ld, ctx, goVersion) Try / catch
g, err := modload.LoadModGraph(ld, ctx, goVersion)
if err != nil {
var ve *module.ModuleError
if errors.As(err, &ve) || strings.Contains(err.Error(), "cannot load module graph") {
// version too old; surface an upgrade prompt rather than retrying blindly
return fmt.Errorf("toolchain too old for module graph: %w (set GOTOOLCHAIN=auto)", err)
}
return err
} Prevention
- Pin CI Go version to >= the highest go directive among dependencies.
- Set GOTOOLCHAIN=auto in CI and dev shells so Go can self-upgrade.
- Do not pass a hand-picked goVersion to LoadModGraph unless you have compared it to the go.mod directive.
- Audit go.mod go directive bumps in code review alongside their required toolchain floor.
When it happens
Trigger: LoadModGraph(ld, ctx, goVersion) is called (directly or by commands like 'go mod graph' / 'go list -m') with goVersion lower than the go.mod's go directive, AND the go.mod directive is at least GoStrictVersion (go1.21+). The comparison gover.Compare(goVersion, v) < 0 trips the error while the root selected version v is itself >= GoStrictVersion.
Common situations: Running an older Go toolchain against a module whose go.mod declares a newer go version; CI pinned to an old Go but the dependency bumped its go directive; forcing -go=go1.19 on a module that requires go1.22; GOPATH toolchain resolution picking an old binary.
Related errors
- module %s listed in go.work file requires go >= %s, but go.w
- non-file URL
- file URL missing path
- file URL specifies non-local host
- file URL encodes volume in host field: too few slashes?
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/b0c4a53875240d35.
Report an issue: GitHub.