{"record":{"id":"799b11e144d34a4f","repo":"golang/go","slug":"s-argument-must-not-be-a-package-in-the-standard","errorCode":null,"errorMessage":"%s: argument must not be a package in the standard library","messagePattern":"(.+?): argument must not be a package in the standard library","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":3413,"sourceCode":"\t\t}\n\t}\n\tpatterns := make([]string, len(args))\n\tfor i, arg := range args {\n\t\tp, found := strings.CutSuffix(arg, \"@\"+version)\n\t\tif !found {\n\t\t\treturn nil, fmt.Errorf(\"%s: all arguments must refer to packages in the same module at the same version (@%s)\", arg, version)\n\t\t}\n\t\tswitch {\n\t\tcase build.IsLocalImport(p):\n\t\t\treturn nil, fmt.Errorf(\"%s: argument must be a package path, not a relative path\", arg)\n\t\tcase filepath.IsAbs(p):\n\t\t\treturn nil, fmt.Errorf(\"%s: argument must be a package path, not an absolute path\", arg)\n\t\tcase search.IsMetaPackage(p):\n\t\t\treturn nil, fmt.Errorf(\"%s: argument must be a package path, not a meta-package\", arg)\n\t\tcase pathpkg.Clean(p) != p:\n\t\t\treturn nil, fmt.Errorf(\"%s: argument must be a clean package path\", arg)\n\t\tcase !strings.Contains(p, \"...\") && search.IsStandardImportPath(p) && modindex.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, p):\n\t\t\treturn nil, fmt.Errorf(\"%s: argument must not be a package in the standard library\", arg)\n\t\tdefault:\n\t\t\tpatterns[i] = p\n\t\t}\n\t}\n\tpatterns = search.CleanPatterns(patterns)\n\n\t// Query the module providing the first argument, load its go.mod file, and\n\t// check that it doesn't contain directives that would cause it to be\n\t// interpreted differently if it were the main module.\n\t//\n\t// If multiple modules match the first argument, accept the longest match\n\t// (first result). It's possible this module won't provide packages named by\n\t// later arguments, and other modules would. Let's not try to be too\n\t// magical though.\n\tallowed := ld.CheckAllowed\n\tif modload.IsRevisionQuery(firstPath, version) {\n\t\t// Don't check for retractions if a specific revision is requested.\n\t\tallowed = nil","sourceCodeStart":3395,"sourceCodeEnd":3431,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L3395-L3431","documentation":"The package@version install workflow (NoRoot mode) cannot target standard library packages, because stdlib packages are versioned with the Go toolchain itself rather than as modules. The path passes `search.IsStandardImportPath` and `modindex.IsStandardPackage`, so the command refuses it.","triggerScenarios":"Running `go install fmt@v1.0.0`, `go install net/http@latest`, or any `pkg@version` where `pkg` resolves to a stdlib package (and the path has no `...` wildcard).","commonSituations":"Confusing a stdlib import path with a third-party module; automation that blindly appends `@version` to any import path; typos that collide with a stdlib package name.","solutions":["Drop the `@version` suffix — stdlib is already part of your toolchain (`go install fmt` is unnecessary).","If you intended a third-party module, correct the import path to the real module path.","For tooling that builds install commands, skip or special-case stdlib paths using `go list std` or `modindex.IsStandardPackage`."],"exampleFix":"// before\ngo install fmt@latest\n\n// after\n// fmt ships with Go; just import it in code. No install needed.","handlingStrategy":"validation","validationCode":"// Before appending @version, exclude stdlib paths.\nfunc isStdlib(p string) bool {\n    // mirrors search.IsStandardImportPath + modindex.IsStandardPackage heuristically\n    if !strings.Contains(p, \".\") {\n        return true // crude but effective for most stdlib paths\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In tooling that builds install commands, skip or special-case stdlib paths.","Cross-reference candidate paths against `go list std` before appending @version.","Treat any path without a dot in the first segment as potentially stdlib."],"tags":["go-toolchain","stdlib","module","install"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}