golang/go · error

no package to get in current directory

Error message

no package to get in current directory

What it means

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'.

Source

Thrown at src/cmd/go/internal/modget/get.go:813

				modRoots := make([]string, 0, len(versions))
				for _, m := range versions {
					modRoots = append(modRoots, ld.MainModules.ModRoot(m))
				}
				var plural string
				if len(modRoots) != 1 {
					plural = "s"
				}
				return errSet(fmt.Errorf("%s%s is not within module%s rooted at %s", q.pattern, absDetail, plural, strings.Join(modRoots, ", ")))
			}

			match := modload.MatchInModule(ld, ctx, pkgPattern, mainModule, imports.AnyTags())
			if len(match.Errs) > 0 {
				return pathSet{err: match.Errs[0]}
			}

			if len(match.Pkgs) == 0 {
				if q.raw == "" || q.raw == "." {
					return errSet(fmt.Errorf("no package to get in current directory"))
				}
				if !q.isWildcard() {
					ld.MustHaveModRoot()
					return errSet(fmt.Errorf("%s%s is not a package in module rooted at %s", q.pattern, absDetail, ld.MainModules.ModRoot(mainModule)))
				}
				search.WarnUnmatched([]*search.Match{match})
				return pathSet{}
			}

			return pathSet{pkgMods: []module.Version{mainModule}}
		})
	}
}

// performWildcardQueries populates the candidates for each query whose pattern
// is a wildcard.
//
// The candidates for a given module path matching (or containing a package

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Navigate to a directory that contains Go source files: 'cd cmd/myapp' then 'go get .'.
  2. Add a .go file to the current directory before running 'go get .'.
  3. Use the full import path instead of '.': 'go get example.com/mymodule/cmd/myapp'.
  4. Verify Go files exist: 'ls *.go' in the current directory.

Example fix

# before
$ cd mymodule/docs
$ go get .
# no package to get in current directory

# after: navigate to a directory with Go files
$ cd ../cmd/myapp
$ go get .
# or add a .go file first
$ touch ../docs/doc.go && go get .
Defensive patterns

Strategy: validation

Validate before calling

// Check if current directory has .go files before 'go get .'
func validateHasGoFiles() error {
    matches, err := filepath.Glob("*.go")
    if err != nil { return err }
    if len(matches) == 0 {
        return fmt.Errorf("no .go files in current directory")
    }
    return nil
}

Try / catch

if strings.Contains(stderr, "no package to get in current directory") {
    // No Go files here; suggest navigating or creating a .go file
}

Prevention

When it happens

Trigger: 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.).

Common situations: 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.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/4c7f64581864a318. Report an issue: GitHub.