golang/go · critical

internal error: a requirement on %v is needed but was not ad

Error message

internal error: a requirement on %v is needed but was not added during package loading (selected %s)

What it means

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.

Source

Thrown at src/cmd/go/internal/modload/load.go:1281

						msg = conflict.String()
					}
					pld.error(errors.New(msg))
				}
			}

			if pld.requirements.pruning == pruned {
				// We continuously add tidy roots to ld.requirements during loading, so
				// at this point the tidy roots (other than possibly the "go" version
				// edited above) should be a subset of the roots of ld.requirements,
				// ensuring that no new dependencies are brought inside the
				// graph-pruning horizon.
				// If that is not the case, there is a bug in the loading loop above.
				for _, m := range rs.rootModules {
					if m.Path == "go" && pld.TidyGoVersion != "" {
						continue
					}
					if v, ok := pld.requirements.rootSelected(ld, m.Path); !ok || v != m.Version {
						pld.error(fmt.Errorf("internal error: a requirement on %v is needed but was not added during package loading (selected %s)", m, v))
					}
				}
			}

			pld.requirements = rs
		}

		pld.exitIfErrors(ctx)
	}

	// Report errors, if any.
	for _, pkg := range pld.pkgs {
		if pkg.err == nil {
			continue
		}

		// Add importer information to checksum errors.
		if sumErr, ok := errors.AsType[*ImportMissingSumError](pkg.err); ok {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Report a bug to the Go project at https://go.dev/issue with the go.mod/go.work contents and Go version.
  2. As a workaround, try 'go mod tidy' after deleting go.sum and the module cache entry for the offending module.
  3. Temporarily downgrade or upgrade your Go toolchain to see if the bug is version-specific.
Defensive patterns

Strategy: try-catch

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/25a288e925415833. Report an issue: GitHub.