golang/go · error
cannot find package in: %s
Error message
cannot find package in: %s
What it means
Stored as a string on rawPackage.error during importRaw when the directory targeted by reldir does not exist on disk. absdir is filepath.Join(modroot, reldir); isDir(absdir) returns false, so the package is reported as not found. Note the error is stored as its .Error() string (not an error value), preserving partial-info semantics for the eventual build.Package.
Source
Thrown at src/cmd/go/internal/modindex/scan.go:192
}
// importRaw fills the rawPackage from the package files in srcDir.
// dir is the package's path relative to the modroot.
func importRaw(modroot, reldir string) *rawPackage {
p := &rawPackage{
dir: reldir,
}
absdir := filepath.Join(modroot, reldir)
// We still haven't checked
// that p.dir directory exists. This is the right time to do that check.
// We can't do it earlier, because we want to gather partial information for the
// non-nil *build.Package returned when an error occurs.
// We need to do this before we return early on FindOnly flag.
if !isDir(absdir) {
// package was not found
p.error = fmt.Errorf("cannot find package in:\n\t%s", absdir).Error()
return p
}
entries, err := fsys.ReadDir(absdir)
if err != nil {
p.error = err.Error()
return p
}
fset := token.NewFileSet()
for _, d := range entries {
if d.IsDir() {
continue
}
if d.Type()&fs.ModeSymlink != 0 {
if isDir(filepath.Join(absdir, d.Name())) {
// Symlinks to directories are not source files.
continueView on GitHub (pinned to b6b368adc5)
Solutions
- Re-sync the module: `go mod download <module>` or `go mod vendor` (if vendored).
- Verify replace directives in go.mod still point at existing local directories.
- Clear the cache and re-resolve: `go clean -modcache && go mod download`.
- Confirm the directory has not been git-cleaned or .gitignored out of the working copy.
Defensive patterns
Strategy: validation
Validate before calling
// Verify the directory exists before triggering importRaw.
func dirExistsUnderModroot(modroot, reldir string) bool {
info, err := os.Stat(filepath.Join(modroot, reldir))
return err == nil && info.IsDir()
} Try / catch
// On 'cannot find package in', refresh the cache or re-vendor once and retry.
pkg, err := buildImport(modroot, reldir)
if err != nil && strings.Contains(err.Error(), "cannot find package in:") {
_ = refreshModule(modroot) // go mod download / vendor
pkg, err = buildImport(modroot, reldir)
} Prevention
- Run `go mod verify` and `go mod vendor` after dependency changes.
- Keep replace directives pointing at directories that actually exist.
- Do not delete files under GOMODCACHE manually.
When it happens
Trigger: importRaw(modroot, reldir) when <modroot>/<reldir> is missing — the index references a directory that has since been deleted, or reldir came from an outdated cache. Also reached when building against a module whose source tree was pruned.
Common situations: Module cache entry was partially deleted; vendor/ tree is out of date relative to go.mod; a replace directive points at a local path that was removed; manual edits to GOMODCACHE.
Related errors
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/3a6e774e55cb3cc8.
Report an issue: GitHub.