{"record":{"id":"283e5e053f01b73d","repo":"golang/go","slug":"can-t-request-explicit-version-q-of-path-q-in-ma","errorCode":null,"errorMessage":"can't request explicit version %q of path %q in main module","messagePattern":"can't request explicit version %q of path %q in main module","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modget/query.go","lineNumber":183,"sourceCode":"\t\tpattern:        pattern,\n\t\tpatternIsLocal: filepath.IsAbs(pattern) || search.IsRelativePath(pattern),\n\t\tversion:        version,\n\t}\n\tif strings.Contains(q.pattern, \"...\") {\n\t\tq.matchWildcard = pkgpattern.MatchPattern(q.pattern)\n\t\tq.canMatchWildcardInModule = pkgpattern.TreeCanMatchPattern(q.pattern)\n\t}\n\tif err := q.validate(ld); err != nil {\n\t\treturn q, err\n\t}\n\treturn q, nil\n}\n\n// validate reports a non-nil error if q is not sensible and well-formed.\nfunc (q *query) validate(ld *modload.Loader) error {\n\tif q.patternIsLocal {\n\t\tif q.rawVersion != \"\" {\n\t\t\treturn fmt.Errorf(\"can't request explicit version %q of path %q in main module\", q.rawVersion, q.pattern)\n\t\t}\n\t\treturn nil\n\t}\n\n\tif q.pattern == \"all\" {\n\t\t// If there is no main module, \"all\" is not meaningful.\n\t\tif !ld.HasModRoot() {\n\t\t\treturn fmt.Errorf(`cannot match \"all\": %v`, modload.NewNoMainModulesError(ld))\n\t\t}\n\t\tif !versionOkForMainModule(q.version) {\n\t\t\t// TODO(bcmills): \"all@none\" seems like a totally reasonable way to\n\t\t\t// request that we remove all module requirements, leaving only the main\n\t\t\t// module and standard library. Perhaps we should implement that someday.\n\t\t\treturn &modload.QueryUpgradesAllError{\n\t\t\t\tMainModules: ld.MainModules.Versions(),\n\t\t\t\tQuery:       q.version,\n\t\t\t}\n\t\t}","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modget/query.go#L165-L201","documentation":"This error occurs when a user specifies a version for a local path pattern (relative paths like './pkg', '../foo', or absolute paths like '/home/user/project'). The query validator detects patternIsLocal (the pattern is a relative or absolute filesystem path) and checks if rawVersion is non-empty. Local paths are part of the main module and cannot have independent versions — they use whatever the main module specifies.","triggerScenarios":"Running 'go get ./mypkg@v1.0.0' or 'go get ../sibling@latest'. The pattern is detected as local (starts with ./, ../, or is absolute), and a version suffix was provided via @version.","commonSituations":"A developer treats a local subpackage as if it were an external module and adds a version. Confusion about the difference between local module paths and external module paths. A script template that always appends @version without checking if the path is local. Migrating from GOPATH mode where local paths might have been versioned differently.","solutions":["Remove the version suffix from local paths: 'go get ./mypkg' instead of 'go get ./mypkg@v1.0.0'.","If you need a specific version of a dependency, use the full module import path (not a relative path): 'go get example.com/mymodule/mypkg@v1.0.0'.","Understand that local paths are resolved relative to the main module and always use the main module's version."],"exampleFix":"# before\n$ go get ./internal/handler@v1.0.0\n# can't request explicit version \"v1.0.0\" of path \"./internal/handler\" in main module\n\n# after: local paths don't take versions\n$ go get ./internal/handler\n# or if you meant an external module, use the full path\n$ go get example.com/mymodule/internal/handler@v1.0.0","handlingStrategy":"validation","validationCode":"// Validate that local path arguments don't have version suffixes\nfunc validateLocalPathNoVersion(arg string) error {\n    parts := strings.SplitN(arg, \"@\", 2)\n    if len(parts) < 2 { return nil } // no version, fine\n    path := parts[0]\n    // Check if path is local (relative or absolute)\n    isLocal := filepath.IsAbs(path) ||\n        strings.HasPrefix(path, \"./\") ||\n        strings.HasPrefix(path, \"../\") ||\n        path == \".\" || path == \"..\"\n    if isLocal {\n        return fmt.Errorf(\"local path %q cannot have version @%s\", path, parts[1])\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(stderr, \"can't request explicit version\") && strings.Contains(stderr, \"in main module\") {\n    // Local path with version suffix\n    // Suggest: remove @version from local paths\n}","preventionTips":["Never append @version to relative or absolute paths in go get","Use full module import paths (e.g., example.com/mypkg) for external dependencies","Distinguish between local paths (./pkg) and module paths (example.com/mypkg)","When scripting, check if a path is local before appending a version suffix"],"tags":["go-get","go-modules","local-path","validation","argument-parsing"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}