{"record":{"id":"25a288e925415833","repo":"golang/go","slug":"internal-error-a-requirement-on-v-is-needed-but","errorCode":null,"errorMessage":"internal error: a requirement on %v is needed but was not added during package loading (selected %s)","messagePattern":"internal error: a requirement on (.+?) is needed but was not added during package loading \\(selected (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/cmd/go/internal/modload/load.go","lineNumber":1281,"sourceCode":"\t\t\t\t\t\tmsg = conflict.String()\n\t\t\t\t\t}\n\t\t\t\t\tpld.error(errors.New(msg))\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif pld.requirements.pruning == pruned {\n\t\t\t\t// We continuously add tidy roots to ld.requirements during loading, so\n\t\t\t\t// at this point the tidy roots (other than possibly the \"go\" version\n\t\t\t\t// edited above) should be a subset of the roots of ld.requirements,\n\t\t\t\t// ensuring that no new dependencies are brought inside the\n\t\t\t\t// graph-pruning horizon.\n\t\t\t\t// If that is not the case, there is a bug in the loading loop above.\n\t\t\t\tfor _, m := range rs.rootModules {\n\t\t\t\t\tif m.Path == \"go\" && pld.TidyGoVersion != \"\" {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif v, ok := pld.requirements.rootSelected(ld, m.Path); !ok || v != m.Version {\n\t\t\t\t\t\tpld.error(fmt.Errorf(\"internal error: a requirement on %v is needed but was not added during package loading (selected %s)\", m, v))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpld.requirements = rs\n\t\t}\n\n\t\tpld.exitIfErrors(ctx)\n\t}\n\n\t// Report errors, if any.\n\tfor _, pkg := range pld.pkgs {\n\t\tif pkg.err == nil {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Add importer information to checksum errors.\n\t\tif sumErr, ok := errors.AsType[*ImportMissingSumError](pkg.err); ok {","sourceCodeStart":1263,"sourceCodeEnd":1299,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/load.go#L1263-L1299","documentation":"An internal-consistency error thrown during tidy root verification (load.go:1281) in pruned requirement mode. After computing tidy roots, the loader checks that every root module (except the 'go' directive version) is present in pld.requirements at the expected selected version. If a root is missing or selected differently, the loading loop has a bug. This should never occur from user input — it signals an internal error in the graph-pruning logic.","triggerScenarios":"Triggered internally when rs.rootModules contains a module not reflected in pld.requirements.rootSelected after the loading loop. The check is gated on pld.requirements.pruning == pruned. This is a defensive assertion, not a user-facing validation.","commonSituations":"This is an internal Go toolchain bug, not a configuration error. It may surface after a Go upgrade with a regression in module graph pruning, or with unusual go.mod topologies that exercise an untested code path.","solutions":["Report a bug to the Go project at https://go.dev/issue with the go.mod/go.work contents and Go version.","As a workaround, try 'go mod tidy' after deleting go.sum and the module cache entry for the offending module.","Temporarily downgrade or upgrade your Go toolchain to see if the bug is version-specific."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["This is an internal Go bug — report it at https://go.dev/issue with full go.mod/go.work and Go version.","As a workaround, clear the module cache ('go clean -cache') and re-run 'go mod tidy'.","Try a different Go toolchain version to see if the bug is version-specific."],"tags":["internal-error","graph-pruning","go-mod-tidy","bug"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}