{"record":{"id":"b0c4a53875240d35","repo":"golang/go","slug":"requested-go-version-s-cannot-load-module-graph","errorCode":null,"errorMessage":"requested Go version %s cannot load module graph (requires Go >= %s)","messagePattern":"requested Go version (.+?) cannot load module graph \\(requires Go >= (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/buildlist.go","lineNumber":568,"sourceCode":"// without loading any packages.\n//\n// If the goVersion string is non-empty, the returned graph is the graph\n// as interpreted by the given Go version (instead of the version indicated\n// in the go.mod file).\n//\n// Modules are loaded automatically (and lazily) in LoadPackages:\n// LoadModGraph need only be called if LoadPackages is not,\n// typically in commands that care about modules but no particular package.\nfunc LoadModGraph(ld *Loader, ctx context.Context, goVersion string) (*ModuleGraph, error) {\n\trs, err := loadModFile(ld, ctx, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif goVersion != \"\" {\n\t\tv, _ := rs.rootSelected(ld, \"go\")\n\t\tif gover.Compare(v, gover.GoStrictVersion) >= 0 && gover.Compare(goVersion, v) < 0 {\n\t\t\treturn nil, fmt.Errorf(\"requested Go version %s cannot load module graph (requires Go >= %s)\", goVersion, v)\n\t\t}\n\n\t\tpruning := pruningForGoVersion(goVersion)\n\t\tif pruning == unpruned && rs.pruning != unpruned {\n\t\t\t// Use newRequirements instead of convertDepth because convertDepth\n\t\t\t// also updates roots; here, we want to report the unmodified roots\n\t\t\t// even though they may seem inconsistent.\n\t\t\trs = newRequirements(ld, unpruned, rs.rootModules, rs.direct)\n\t\t}\n\n\t\treturn rs.Graph(ld, ctx)\n\t}\n\n\trs, mg, err := expandGraph(ld, ctx, rs)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tld.requirements = rs","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/buildlist.go#L550-L586","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$ GOTOOLCHAIN=go1.19 go mod graph  // module go.mod says 'go 1.22'\n// error: requested Go version go1.19 cannot load module graph (requires Go >= 1.22)\n\n// after\n$ GOTOOLCHAIN=auto go mod graph          // let it pick >= 1.22\n// or edit go.mod:  go 1.19               // if you accept the downgrade","handlingStrategy":"validation","validationCode":"// Before calling LoadModGraph, ensure goVersion is >= the go.mod directive.\nif goVersion != \"\" {\n    if v, ok := rs.rootSelected(ld, \"go\"); ok {\n        if gover.Compare(v, gover.GoStrictVersion) >= 0 && gover.Compare(goVersion, v) < 0 {\n            return nil, fmt.Errorf(\"refusing to call LoadModGraph: %s < required %s\", goVersion, v)\n        }\n    }\n}\nreturn LoadModGraph(ld, ctx, goVersion)","typeGuard":null,"tryCatchPattern":"g, err := modload.LoadModGraph(ld, ctx, goVersion)\nif err != nil {\n    var ve *module.ModuleError\n    if errors.As(err, &ve) || strings.Contains(err.Error(), \"cannot load module graph\") {\n        // version too old; surface an upgrade prompt rather than retrying blindly\n        return fmt.Errorf(\"toolchain too old for module graph: %w (set GOTOOLCHAIN=auto)\", err)\n    }\n    return err\n}","preventionTips":["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."],"tags":["go-toolchain","module-graph","version-mismatch","gover"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}