{"record":{"id":"8a735ce9e1faff42","repo":"golang/go","slug":"s-failed-to-load-from-any-module-but-go-s-woul","errorCode":null,"errorMessage":"%s failed to load from any module,\n\tbut go %s would load it from %v","messagePattern":"(.+?) failed to load from any module,\n\tbut go (.+?) would load it from (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/load.go","lineNumber":2246,"sourceCode":"\n\t\tcase pkg.err != nil:\n\t\t\t// pkg had an error in with a pruned module graph (presumably suppressed\n\t\t\t// with the -e flag), but the error went away using an unpruned graph.\n\t\t\t//\n\t\t\t// This is possible, if, say, the import is unresolved in the pruned graph\n\t\t\t// (because the \"latest\" version of each candidate module either is\n\t\t\t// unavailable or does not contain the package), but is resolved in the\n\t\t\t// unpruned graph due to a newer-than-latest dependency that is normally\n\t\t\t// pruned out.\n\t\t\t//\n\t\t\t// This could also occur if the source code for the module providing the\n\t\t\t// package in the pruned graph has a checksum error, but the unpruned\n\t\t\t// graph upgrades that module to a version with a correct checksum.\n\t\t\t//\n\t\t\t// pkg.err should have already been logged elsewhere — along with a\n\t\t\t// stack trace — so log only the import path and non-error info here.\n\t\t\tsuggestUpgrade = true\n\t\t\tpld.error(fmt.Errorf(\"%s failed to load from any module,\\n\\tbut go %s would load it from %v\", pkg.path, compatVersion, mismatch.mod))\n\n\t\tcase pkg.mod != mismatch.mod:\n\t\t\t// The package is loaded successfully by both Go versions, but from a\n\t\t\t// different module in each. This could lead to subtle (and perhaps even\n\t\t\t// unnoticed!) variations in behavior between builds with different\n\t\t\t// toolchains.\n\t\t\tsuggestUpgrade = true\n\t\t\tpld.error(fmt.Errorf(\"%s loaded from %v,\\n\\tbut go %s would select %v\\n\", pkg.stackText(), pkg.mod, compatVersion, mismatch.mod.Version))\n\n\t\tdefault:\n\t\t\tbase.Fatalf(\"go: internal error: mismatch recorded for package %s, but no differences found\", pkg.path)\n\t\t}\n\t}\n\n\tpld.switchIfErrors(ctx)\n\tsuggestFixes()\n\tpld.exitIfErrors(ctx)\n}","sourceCodeStart":2228,"sourceCodeEnd":2264,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/load.go#L2228-L2264","documentation":"Emitted by 'go mod tidy' compatibility check. The package failed to load under the current (pruned) module graph — its underlying pkg.err was already reported separately — but when the import is re-resolved under the older Go version's unpruned requirements, it loads successfully from mismatch.mod. This means an older Go would build code that the current toolchain cannot resolve.","triggerScenarios":"Running 'go mod tidy' where the package is unresolved in the pruned graph (latest candidate module unavailable or missing the package, or a checksum error in source) but a newer-than-latest transitive dependency normally pruned out provides it in the unpruned graph.","commonSituations":"A dependency bumped its go.mod to 1.17+ so its transitive requirements are pruned for your module, hiding the version that actually provides the import; a module proxy serving a stale 'latest'; source checksum mismatch on the pruned version that the unpruned graph upgrades past.","solutions":["Upgrade to the older toolchain's selected versions per the printed hint: 'go mod tidy -go=<compatVersion> && go mod tidy'.","Run 'go mod tidy -e' to tolerate the unresolved package and inspect which module 'go %s would load it from' (mismatch.mod) via 'go list -m -json <mismatch.mod>'.","Add an explicit require for the module/version named by mismatch.mod so it is no longer pruned out.","If older-Go reproducibility is unnecessary, rebuild with 'go mod tidy -compat=<yourGoVersion>'."],"exampleFix":"// before\n$ go mod tidy\n// error: example.com/pkg failed to load from any module,\n// \tbut go 1.20 would load it from example.com/mod@v1.4.0\n\n// after: pin the version the older graph selected\n$ go get example.com/mod@v1.4.0 && go mod tidy","handlingStrategy":"validation","validationCode":"// Detect that every import resolves in the compat graph before tidy:\n//   go mod tidy -go=<compat> -e 2>&1 | grep 'failed to load from any module'\n// If non-empty, add an explicit require for the module printed in the hint.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer explicit 'go get <mod>@<ver>' over relying on transitive resolution.","Avoid mixing pruned (go >= 1.17) and unpruned dependencies without testing both graphs.","Run 'go mod verify' periodically to catch checksum issues that diverge between graphs."],"tags":["go-modules","go-mod-tidy","graph-pruning","compatibility","missing-import"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}