{"record":{"id":"4c7f64581864a318","repo":"golang/go","slug":"no-package-to-get-in-current-directory","errorCode":null,"errorMessage":"no package to get in current directory","messagePattern":"no package to get in current directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modget/get.go","lineNumber":813,"sourceCode":"\t\t\t\tmodRoots := make([]string, 0, len(versions))\n\t\t\t\tfor _, m := range versions {\n\t\t\t\t\tmodRoots = append(modRoots, ld.MainModules.ModRoot(m))\n\t\t\t\t}\n\t\t\t\tvar plural string\n\t\t\t\tif len(modRoots) != 1 {\n\t\t\t\t\tplural = \"s\"\n\t\t\t\t}\n\t\t\t\treturn errSet(fmt.Errorf(\"%s%s is not within module%s rooted at %s\", q.pattern, absDetail, plural, strings.Join(modRoots, \", \")))\n\t\t\t}\n\n\t\t\tmatch := modload.MatchInModule(ld, ctx, pkgPattern, mainModule, imports.AnyTags())\n\t\t\tif len(match.Errs) > 0 {\n\t\t\t\treturn pathSet{err: match.Errs[0]}\n\t\t\t}\n\n\t\t\tif len(match.Pkgs) == 0 {\n\t\t\t\tif q.raw == \"\" || q.raw == \".\" {\n\t\t\t\t\treturn errSet(fmt.Errorf(\"no package to get in current directory\"))\n\t\t\t\t}\n\t\t\t\tif !q.isWildcard() {\n\t\t\t\t\tld.MustHaveModRoot()\n\t\t\t\t\treturn errSet(fmt.Errorf(\"%s%s is not a package in module rooted at %s\", q.pattern, absDetail, ld.MainModules.ModRoot(mainModule)))\n\t\t\t\t}\n\t\t\t\tsearch.WarnUnmatched([]*search.Match{match})\n\t\t\t\treturn pathSet{}\n\t\t\t}\n\n\t\t\treturn pathSet{pkgMods: []module.Version{mainModule}}\n\t\t})\n\t}\n}\n\n// performWildcardQueries populates the candidates for each query whose pattern\n// is a wildcard.\n//\n// The candidates for a given module path matching (or containing a package","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modget/get.go#L795-L831","documentation":"This error occurs when 'go get .' (or 'go get' with an empty pattern, or 'go get \"\"') is run in a directory that is inside a module root but contains no Go source files. The match lookup (MatchInModule) returns zero packages, and since the raw query was '.' or empty, the code reports 'no package to get in current directory'.","triggerScenarios":"Running 'go get .' in a directory within a module that has no .go files. An empty subdirectory of a module. A directory that only contains non-Go files (README, config, etc.).","commonSituations":"A developer runs 'go get .' from a documentation or assets directory that has no Go files. A freshly created module where the source file hasn't been added yet. Running 'go get .' from a vendor or build-output subdirectory that has no Go source.","solutions":["Navigate to a directory that contains Go source files: 'cd cmd/myapp' then 'go get .'.","Add a .go file to the current directory before running 'go get .'.","Use the full import path instead of '.': 'go get example.com/mymodule/cmd/myapp'.","Verify Go files exist: 'ls *.go' in the current directory."],"exampleFix":"# before\n$ cd mymodule/docs\n$ go get .\n# no package to get in current directory\n\n# after: navigate to a directory with Go files\n$ cd ../cmd/myapp\n$ go get .\n# or add a .go file first\n$ touch ../docs/doc.go && go get .","handlingStrategy":"validation","validationCode":"// Check if current directory has .go files before 'go get .'\nfunc validateHasGoFiles() error {\n    matches, err := filepath.Glob(\"*.go\")\n    if err != nil { return err }\n    if len(matches) == 0 {\n        return fmt.Errorf(\"no .go files in current directory\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(stderr, \"no package to get in current directory\") {\n    // No Go files here; suggest navigating or creating a .go file\n}","preventionTips":["Verify .go files exist with 'ls *.go' before 'go get .'","Navigate to the correct package directory before running go get .","Create a doc.go placeholder if the directory should be a package","Use 'go list ./...' to find packages within your module"],"tags":["go-get","go-modules","local-path","no-packages"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}