golang/go · error
%s%s is not a package in module rooted at %s
Error message
%s%s is not a package in module rooted at %s
What it means
This error occurs when a non-wildcard local path query resolves inside a module but matches no Go packages. Unlike the '.' case (error 1033), this fires for explicit local paths like './subdir' or '../pkg' that aren't wildcards. The match lookup returns zero packages and the pattern is not '.', so the code reports that the specific path doesn't correspond to a package in the module.
Source
Thrown at src/cmd/go/internal/modget/get.go:817
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
// matching) a wildcard query depend only on the initial build list, but the set
// of modules may be expanded by other queries, so wildcard queries need to be
// re-evaluated whenever a potentially-matching module path is added to the
// build list.View on GitHub (pinned to b6b368adc5)
Solutions
- Verify the directory exists and contains Go files: 'ls ./subdir/*.go'.
- Use a wildcard to find available packages: 'go list ./...' to see what packages exist in the module.
- Check for typos in the path. Try 'go get ./subdir/...' if you want a wildcard match.
- Ensure build tags or build constraints aren't excluding all .go files in the target directory.
Example fix
# before $ go get ./cmd/nonexistent # ./cmd/nonexistent is not a package in module rooted at /home/user/myproject # after: find the correct package $ go list ./... # example.com/myproject/cmd/server # example.com/myproject/cmd/cli $ go get ./cmd/server
Defensive patterns
Strategy: validation
Validate before calling
// Verify a local path resolves to a directory with Go files
func validateLocalPackagePath(pattern string) error {
absPath, err := filepath.Abs(pattern)
if err != nil { return err }
info, err := os.Stat(absPath)
if err != nil { return fmt.Errorf("path %s does not exist: %w", pattern, err) }
if !info.IsDir() { return fmt.Errorf("%s is not a directory", pattern) }
matches, _ := filepath.Glob(filepath.Join(absPath, "*.go"))
if len(matches) == 0 {
return fmt.Errorf("no .go files in %s", absPath)
}
return nil
} Try / catch
if strings.Contains(stderr, "is not a package in module") {
// Path resolves to a dir with no Go files
// Suggest: go list ./... to find valid packages
} Prevention
- Verify paths exist and contain .go files before using them in go get
- Use 'go list ./...' to discover available packages in the module
- Check for typos in relative paths
- Be aware of build tags that might exclude .go files
When it happens
Trigger: Running 'go get ./nonexistent' or 'go get ./subdir' where subdir has no .go files or doesn't exist within the module. A specific relative path that resolves to a directory without Go packages.
Common situations: A developer types a relative subdirectory path that doesn't contain any Go files. A path to a directory that was renamed or deleted. A typo in the relative path. A directory containing only test files (_test.go) when using build tags that exclude them.
Related errors
- no package to get in current directory
- %s%s is not within module%s rooted at %s
- can't request explicit version %q of path %q in main module
- %v matches packages in %v but not %v: specify a different ve
- invalid module version syntax %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/fd54da9c7f42ee16.
Report an issue: GitHub.