{"record":{"id":"1821e63ce39172b4","repo":"golang/go","slug":"can-t-request-explicit-version-q-of-standard-libr","errorCode":null,"errorMessage":"can't request explicit version %q of standard library package %s","messagePattern":"can't request explicit version %q of standard library package (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modget/get.go","lineNumber":1071,"sourceCode":"// queryPath adds a candidate set to q for the package with path q.pattern.\n// The candidate set consists of all modules that could provide q.pattern\n// and have a version matching q, plus (if it exists) the module whose path\n// is itself q.pattern (at a matching version).\nfunc (r *resolver) queryPath(ld *modload.Loader, ctx context.Context, q *query) {\n\tq.pathOnce(q.pattern, func() pathSet {\n\t\tif search.IsMetaPackage(q.pattern) || q.isWildcard() {\n\t\t\tpanic(fmt.Sprintf(\"internal error: queryPath called with pattern %q\", q.pattern))\n\t\t}\n\t\tif q.version == \"none\" {\n\t\t\tpanic(`internal error: queryPath called with version \"none\"`)\n\t\t}\n\n\t\tif search.IsStandardImportPath(q.pattern) {\n\t\t\tstdOnly := module.Version{}\n\t\t\tpackages, _ := r.matchInModule(ld, ctx, q.pattern, stdOnly)\n\t\t\tif len(packages) > 0 {\n\t\t\t\tif q.rawVersion != \"\" {\n\t\t\t\t\treturn errSet(fmt.Errorf(\"can't request explicit version %q of standard library package %s\", q.version, q.pattern))\n\t\t\t\t}\n\n\t\t\t\tq.matchesPackages = true\n\t\t\t\treturn pathSet{} // No module needed for standard library.\n\t\t\t}\n\t\t}\n\n\t\tpkgMods, mod, err := r.queryPattern(ld, ctx, q.pattern, q.version, r.initialSelected)\n\t\tif err != nil {\n\t\t\treturn errSet(err)\n\t\t}\n\t\treturn pathSet{pkgMods: pkgMods, mod: mod}\n\t})\n}\n\n// performToolQueries populates the candidates for each query whose\n// pattern is \"tool\".\nfunc (r *resolver) performToolQueries(ld *modload.Loader, ctx context.Context) {","sourceCodeStart":1053,"sourceCodeEnd":1089,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modget/get.go#L1053-L1089","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","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.","Simply import the package in your code — no go get needed: 'import \"fmt\"' works out of the box."],"exampleFix":"# before\n$ go get net/http@latest\n# can't request explicit version \"latest\" of standard library package net/http\n\n# after: just import it directly, no go get needed\n# In your .go file:\nimport \"net/http\"  // works without any go get\n\n# or if you want a different stdlib version, change the toolchain\n$ go get go@1.21.0","handlingStrategy":"validation","validationCode":"// Validate that a go get argument is not a stdlib package with a version\nfunc validateNotStdlibWithVersion(arg string) error {\n    parts := strings.SplitN(arg, \"@\", 2)\n    if len(parts) < 2 { return nil } // no version, fine\n    path := parts[0]\n    firstElem := path\n    if idx := strings.Index(path, \"/\"); idx >= 0 {\n        firstElem = path[:idx]\n    }\n    // Stdlib import paths have no dot in the first element\n    if !strings.Contains(firstElem, \".\") {\n        return fmt.Errorf(\"%s looks like a stdlib package; remove @%s\", path, parts[1])\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(stderr, \"can't request explicit version\") && strings.Contains(stderr, \"standard library\") {\n    // User tried to version a stdlib package\n    // Suggest: remove the @version suffix or import directly\n}","preventionTips":["Never append @version to standard library import paths","Stdlib packages have no dot in the first path element (fmt, net/http, os)","Simply import stdlib packages directly — no go get needed","Educate team members about the difference between stdlib and external packages"],"tags":["go-get","stdlib","go-version","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}