golang/go · error

can't request explicit version %q of standard library packag

Error message

can't request explicit version %q of standard library package %s

What it means

This error occurs when a user tries to request a specific version of a Go standard library package using 'go get'. The code checks IsStandardImportPath (no dot in the first path element), then verifies packages exist in the standard library. If they do, and q.rawVersion is non-empty (the user specified @version), it errors because standard library packages are part of the Go toolchain itself and cannot be versioned independently.

Source

Thrown at src/cmd/go/internal/modget/get.go:1071

// queryPath adds a candidate set to q for the package with path q.pattern.
// The candidate set consists of all modules that could provide q.pattern
// and have a version matching q, plus (if it exists) the module whose path
// is itself q.pattern (at a matching version).
func (r *resolver) queryPath(ld *modload.Loader, ctx context.Context, q *query) {
	q.pathOnce(q.pattern, func() pathSet {
		if search.IsMetaPackage(q.pattern) || q.isWildcard() {
			panic(fmt.Sprintf("internal error: queryPath called with pattern %q", q.pattern))
		}
		if q.version == "none" {
			panic(`internal error: queryPath called with version "none"`)
		}

		if search.IsStandardImportPath(q.pattern) {
			stdOnly := module.Version{}
			packages, _ := r.matchInModule(ld, ctx, q.pattern, stdOnly)
			if len(packages) > 0 {
				if q.rawVersion != "" {
					return errSet(fmt.Errorf("can't request explicit version %q of standard library package %s", q.version, q.pattern))
				}

				q.matchesPackages = true
				return pathSet{} // No module needed for standard library.
			}
		}

		pkgMods, mod, err := r.queryPattern(ld, ctx, q.pattern, q.version, r.initialSelected)
		if err != nil {
			return errSet(err)
		}
		return pathSet{pkgMods: pkgMods, mod: mod}
	})
}

// performToolQueries populates the candidates for each query whose
// pattern is "tool".
func (r *resolver) performToolQueries(ld *modload.Loader, ctx context.Context) {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Remove the version specifier: 'go get fmt' instead of 'go get fmt@latest'. Note that 'go get' of stdlib packages is typically unnecessary — just import them directly in code.
  2. If you need a specific stdlib version, upgrade/downgrade the entire Go toolchain: 'go get go@1.21.0' or install a specific Go version.
  3. Simply import the package in your code — no go get needed: 'import "fmt"' works out of the box.

Example fix

# before
$ go get net/http@latest
# can't request explicit version "latest" of standard library package net/http

# after: just import it directly, no go get needed
# In your .go file:
import "net/http"  // works without any go get

# or if you want a different stdlib version, change the toolchain
$ go get go@1.21.0
Defensive patterns

Strategy: validation

Validate before calling

// Validate that a go get argument is not a stdlib package with a version
func validateNotStdlibWithVersion(arg string) error {
    parts := strings.SplitN(arg, "@", 2)
    if len(parts) < 2 { return nil } // no version, fine
    path := parts[0]
    firstElem := path
    if idx := strings.Index(path, "/"); idx >= 0 {
        firstElem = path[:idx]
    }
    // Stdlib import paths have no dot in the first element
    if !strings.Contains(firstElem, ".") {
        return fmt.Errorf("%s looks like a stdlib package; remove @%s", path, parts[1])
    }
    return nil
}

Try / catch

if strings.Contains(stderr, "can't request explicit version") && strings.Contains(stderr, "standard library") {
    // User tried to version a stdlib package
    // Suggest: remove the @version suffix or import directly
}

Prevention

When it happens

Trigger: Running a command like 'go get fmt@1.20', 'go get net/http@latest', or 'go get os@v1.2.3'. The pattern matches a standard library import path, packages are found in std, but an explicit version was requested via @version syntax.

Common situations: A developer unfamiliar with Go modules tries to 'go get' a stdlib package with a version. Confusion about which packages are third-party vs standard library. Accidentally adding @latest to a stdlib import path in a script. Copying a go get command from documentation that was meant for external packages.

Related errors


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