golang/go · error

can't request explicit version of standard-library pattern %

Error message

can't request explicit version of standard-library pattern %q

What it means

Returned by query.validate when the pattern is a standard-library meta-package other than 'all'/'tool' (e.g. 'std', 'cmd') AND an explicit @version was supplied. Standard-library packages ship with the toolchain and cannot be fetched at a chosen module version. The %q slot is the offending pattern name.

Source

Thrown at src/cmd/go/internal/modget/query.go:209

			return fmt.Errorf(`cannot match "all": %v`, modload.NewNoMainModulesError(ld))
		}
		if !versionOkForMainModule(q.version) {
			// TODO(bcmills): "all@none" seems like a totally reasonable way to
			// request that we remove all module requirements, leaving only the main
			// module and standard library. Perhaps we should implement that someday.
			return &modload.QueryUpgradesAllError{
				MainModules: ld.MainModules.Versions(),
				Query:       q.version,
			}
		}
	}

	if search.IsMetaPackage(q.pattern) && q.pattern != "all" {
		if q.pattern != q.raw {
			if q.pattern == "tool" {
				return fmt.Errorf("can't request explicit version of \"tool\" pattern")
			}
			return fmt.Errorf("can't request explicit version of standard-library pattern %q", q.pattern)
		}
	}

	return nil
}

// String returns the original argument from which q was parsed.
func (q *query) String() string { return q.raw }

// ResolvedString returns a string describing m as a resolved match for q.
func (q *query) ResolvedString(m module.Version) string {
	if m.Path != q.pattern {
		if m.Version != q.version {
			return fmt.Sprintf("%v (matching %s@%s)", m, q.pattern, q.version)
		}
		return fmt.Sprintf("%v (matching %v)", m, q)
	}
	if m.Version != q.version {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Remove the @version suffix when fetching standard-library meta-packages.
  2. To change which standard library you compile against, switch the active Go toolchain (e.g. `go get go@1.20`) instead of pinning 'std'.
  3. If you need a specific std package at a specific version, vendor it into your module under a separate import path.

Example fix

// before
$ go get std@1.20
// after
$ go get go@1.20   # switches the toolchain (and thus std)
Defensive patterns

Strategy: validation

Validate before calling

// Mirror of modget.query.validate for std meta-packages.
func rejectStdVersion(arg string) error {
    pkg, ver, _ := strings.Cut(arg, "@")
    std := map[string]bool{"std": true, "cmd": true}
    if ver != "" && std[pkg] {
        return fmt.Errorf("cannot pin standard-library meta-package %q; switch toolchain instead", pkg)
    }
    return nil
}

Prevention

When it happens

Trigger: Running `go get std@1.20`, `go get cmd@latest`, or any query whose raw form carries a version but whose normalized pattern is a standard-library meta-package. Reached from query.validate in the else-branch after the 'tool' check.

Common situations: Mistakenly treating 'std' or 'cmd' as importable modules; attempting to downgrade the standard library to match an older Go release.

Related errors


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