{"record":{"id":"dd124531fa99e0aa","repo":"golang/go","slug":"s-argument-must-be-a-package-path-not-a-relativ","errorCode":null,"errorMessage":"%s: argument must be a package path, not a relative path","messagePattern":"(.+?): argument must be a package path, not a relative path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":3405,"sourceCode":"\tvar firstPath string\n\tfor _, arg := range args {\n\t\tif i := strings.Index(arg, \"@\"); i >= 0 {\n\t\t\tfirstPath, version = arg[:i], arg[i+1:]\n\t\t\tif version == \"\" {\n\t\t\t\treturn nil, fmt.Errorf(\"%s: version must not be empty\", arg)\n\t\t\t}\n\t\t\tbreak\n\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//","sourceCodeStart":3387,"sourceCodeEnd":3423,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L3387-L3423","documentation":"Returned by PackagesAndErrorsOutsideModule (line 3405). After stripping the @version suffix, the remaining path is checked: build.IsLocalImport(p) is true when p is `.` or starts with `./` or `../`. `go install pkg@version` cannot target a local relative import because there is no well-defined module/version for it. The arg as written (with @version) is echoed.","triggerScenarios":"Running `go install ./cmd/app@v1.0.0`, `go install .@latest`, or `go install ../lib@v2`. The function only accepts fully-qualified module paths.","commonSituations":"Confusing `go install ./pkg` (local install, no @version allowed) with `go install pkg@version` (remote, must be a module path); muscle memory from `go run ./...`.","solutions":["For a local package, drop the @version: `go install ./cmd/app`.","For a published package, use its full module path: `go install example.com/app/cmd/app@v1.0.0`."],"exampleFix":"# before\ngo install ./cmd/app@v1.0.0\n# after  (local)\ngo install ./cmd/app\n# after  (remote)\ngo install example.com/app/cmd/app@v1.0.0","handlingStrategy":"validation","validationCode":"// Reject relative imports in `go install pkg@version` args.\npackage argcheck\n\nimport (\n\t\"errors\"\n\t\"strings\"\n)\n\nfunc NotRelativeImport(arg string) error {\n\tp := arg\n\tif i := strings.Index(arg, \"@\"); i >= 0 {\n\t\tp = arg[:i]\n\t}\n\tif p == \".\" || strings.HasPrefix(p, \"./\") || strings.HasPrefix(p, \"../\") {\n\t\treturn errors.New(\"relative path not allowed with @version: \" + arg)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember: `go install pkg@version` takes a module path; local installs use `go install ./pkg` with NO @version.","Never templatize `go install $PATH@$VER` with a relative $PATH."],"tags":["modules","go-install","cli","toolchain"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}