{"record":{"id":"ab99424de3472157","repo":"golang/go","slug":"cannot-find-package","errorCode":null,"errorMessage":"cannot find package","messagePattern":"cannot find package","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/load.go","lineNumber":1066,"sourceCode":"func (af *atomicLoadPkgFlags) has(cond loadPkgFlags) bool {\n\treturn loadPkgFlags(af.bits.Load())&cond == cond\n}\n\n// isTest reports whether pkg is a test of another package.\nfunc (pkg *loadPkg) isTest() bool {\n\treturn pkg.testOf != nil\n}\n\n// fromExternalModule reports whether pkg was loaded from a module other than\n// the main module.\nfunc (pkg *loadPkg) fromExternalModule(ld *Loader) bool {\n\tif pkg.mod.Path == \"\" {\n\t\treturn false // loaded from the standard library, not a module\n\t}\n\treturn !ld.MainModules.Contains(pkg.mod.Path)\n}\n\nvar errMissing = errors.New(\"cannot find package\")\n\n// loadFromRoots attempts to load the build graph needed to process a set of\n// root packages and their dependencies.\n//\n// The set of root packages is returned by the params.listRoots function, and\n// expanded to the full set of packages by tracing imports (and possibly tests)\n// as needed.\nfunc loadFromRoots(ld *Loader, ctx context.Context, params loaderParams) *packageLoader {\n\tpld := &packageLoader{\n\t\tloaderParams: params,\n\t\twork:         par.NewQueue(runtime.GOMAXPROCS(0)),\n\t}\n\n\tif pld.requirements.pruning == unpruned {\n\t\t// If the module graph does not support pruning, we assume that we will need\n\t\t// the full module graph in order to load package dependencies.\n\t\t//\n\t\t// This might not be strictly necessary, but it matches the historical","sourceCodeStart":1048,"sourceCodeEnd":1084,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/load.go#L1048-L1084","documentation":"errMissing is the loader's generic sentinel raised when no package can be found for a requested import path: not in the standard library, not in the module graph, and not resolvable from source. It is the bottom-of-the-stack answer for an unresolvable import.","triggerScenarios":"Loading/building/importing a path that does not exist, cannot be downloaded, is excluded, or is not in any active module's dependency graph.","commonSituations":"Import-path typos; missing `go get`; private modules without GOPRIVATE/GONOSUMDB/GOPROXY config; network/proxy outages; replace directives pointing at deleted paths.","solutions":["Add the package: `go get <importpath>`.","Check the import path spelling and casing.","For private repos set GOPRIVATE (and GOPROXY/NOPROXY) appropriately.","Verify any replace/exclude directives aren't hiding the package."],"exampleFix":"// before\nimport \"example.com/nothing\"   // cannot find package\n\n// after\n$ go get example.com/nothing","handlingStrategy":"validation","validationCode":"// Sanity-check that an import path resolves before building.\nfunc importResolves(path string) error {\n    return exec.Command(\"go\", \"list\", path).Run()\n}","typeGuard":"// Narrow a sentinel 'cannot find package' error.\nimport \"errors\"\n\nfunc isMissingPackage(err error) bool {\n    return errors.Is(err, errMissing) // exported equivalent in your wrapper\n}","tryCatchPattern":"if err := importer.Default().Import(path); err != nil {\n    if isMissingPackage(err) { /* go get it, then retry */ }\n}","preventionTips":["Run `go mod tidy` to ensure all imports are tracked.","Configure GOPRIVATE/GOPROXY for private and proxied modules.","Validate import paths before CI build steps."],"tags":["import","module-resolution","missing-package","loader"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}