{"record":{"id":"3a6e774e55cb3cc8","repo":"golang/go","slug":"cannot-find-package-in-s","errorCode":null,"errorMessage":"cannot find package in:\n\t%s","messagePattern":"cannot find package in:\n\t(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modindex/scan.go","lineNumber":192,"sourceCode":"}\n\n// importRaw fills the rawPackage from the package files in srcDir.\n// dir is the package's path relative to the modroot.\nfunc importRaw(modroot, reldir string) *rawPackage {\n\tp := &rawPackage{\n\t\tdir: reldir,\n\t}\n\n\tabsdir := filepath.Join(modroot, reldir)\n\n\t// We still haven't checked\n\t// that p.dir directory exists. This is the right time to do that check.\n\t// We can't do it earlier, because we want to gather partial information for the\n\t// non-nil *build.Package returned when an error occurs.\n\t// We need to do this before we return early on FindOnly flag.\n\tif !isDir(absdir) {\n\t\t// package was not found\n\t\tp.error = fmt.Errorf(\"cannot find package in:\\n\\t%s\", absdir).Error()\n\t\treturn p\n\t}\n\n\tentries, err := fsys.ReadDir(absdir)\n\tif err != nil {\n\t\tp.error = err.Error()\n\t\treturn p\n\t}\n\n\tfset := token.NewFileSet()\n\tfor _, d := range entries {\n\t\tif d.IsDir() {\n\t\t\tcontinue\n\t\t}\n\t\tif d.Type()&fs.ModeSymlink != 0 {\n\t\t\tif isDir(filepath.Join(absdir, d.Name())) {\n\t\t\t\t// Symlinks to directories are not source files.\n\t\t\t\tcontinue","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modindex/scan.go#L174-L210","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the directory exists before triggering importRaw.\nfunc dirExistsUnderModroot(modroot, reldir string) bool {\n    info, err := os.Stat(filepath.Join(modroot, reldir))\n    return err == nil && info.IsDir()\n}","typeGuard":null,"tryCatchPattern":"// On 'cannot find package in', refresh the cache or re-vendor once and retry.\npkg, err := buildImport(modroot, reldir)\nif err != nil && strings.Contains(err.Error(), \"cannot find package in:\") {\n    _ = refreshModule(modroot) // go mod download / vendor\n    pkg, err = buildImport(modroot, reldir)\n}","preventionTips":["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."],"tags":["module-index","filesystem","not-found","vendor"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}