{"record":{"id":"4e5a9187540d2b5e","repo":"golang/go","slug":"unknown-import-path-q-internal-error-module-loa","errorCode":null,"errorMessage":"unknown import path %q: internal error: module loader did not resolve import","messagePattern":"unknown import path %q: internal error: module loader did not resolve import","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":979,"sourceCode":"\t\t\t\t\t// loader said there weren't. Which one is right?\n\t\t\t\t\t// Without this special-case hack, the TestScript/test_vet case fails\n\t\t\t\t\t// on the vetfail/p1 package (added in CL 83955).\n\t\t\t\t\t// Apparently, imports.ShouldBuild biases toward rejecting files\n\t\t\t\t\t// with invalid build constraints, whereas ImportDir biases toward\n\t\t\t\t\t// accepting them.\n\t\t\t\t\t//\n\t\t\t\t\t// TODO(#41410: Figure out how this actually ought to work and fix\n\t\t\t\t\t// this mess).\n\t\t\t\t} else {\n\t\t\t\t\tdata.err = r.err\n\t\t\t\t}\n\t\t\t}\n\t\t} else if r.err != nil {\n\t\t\tdata.p = new(build.Package)\n\t\t\tdata.err = r.err\n\t\t} else if cfg.ModulesEnabled && path != \"unsafe\" {\n\t\t\tdata.p = new(build.Package)\n\t\t\tdata.err = fmt.Errorf(\"unknown import path %q: internal error: module loader did not resolve import\", r.path)\n\t\t} else {\n\t\t\tbuildMode := build.ImportComment\n\t\t\tif mode&ResolveImport == 0 || r.path != path {\n\t\t\t\t// Not vendoring, or we already found the vendored path.\n\t\t\t\tbuildMode |= build.IgnoreVendor\n\t\t\t}\n\t\t\tdata.p, data.err = cfg.BuildContext.Import(r.path, parentDir, buildMode)\n\t\t}\n\t\tdata.p.ImportPath = r.path\n\n\t\t// Set data.p.BinDir in cases where go/build.Context.Import\n\t\t// may give us a path we don't want.\n\t\tif !data.p.Goroot {\n\t\t\tif cfg.GOBIN != \"\" {\n\t\t\t\tdata.p.BinDir = cfg.GOBIN\n\t\t\t} else if cfg.ModulesEnabled {\n\t\t\t\tdata.p.BinDir = modload.BinDir(ld)\n\t\t\t}","sourceCodeStart":961,"sourceCodeEnd":997,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L961-L997","documentation":"In module-aware mode (cfg.ModulesEnabled is true), the module loader is expected to resolve every import except 'unsafe'. This error means the resolver returned a result object without setting r.err, but also without producing a resolved package — a condition loadPackageData treats as an internal toolchain bug. The 'internal error' label in the message signals this should not happen under normal use.","triggerScenarios":"An import that the module resolver silently failed on, returning neither a resolved path nor an error. This indicates corruption in the module cache, a go.sum inconsistency that was silently swallowed, or a genuine bug in the Go toolchain's module resolution path. Only triggers when path != \"unsafe\" and ModulesEnabled is true.","commonSituations":"Corrupted module cache ($GOPATH/pkg/mod) after a failed download or disk issue. Network issues during module download that left partial state. Inconsistent go.mod/go.sum after a failed go mod operation. Using a patched or development Go toolchain with resolution bugs.","solutions":["Run go mod tidy to re-resolve dependencies and fix go.sum inconsistencies.","Clear the module cache: go clean -modcache, then re-download with go mod download.","Update to the latest Go patch release — this may be a known toolchain bug that has been fixed.","If reproducible, file a bug at https://github.com/golang/go/issues with go.mod, the import graph, and Go version."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-validate module resolution before building.\nfunc checkModuleResolution() error {\n    cmd := exec.Command(\"go\", \"mod\", \"verify\")\n    if out, err := cmd.CombinedOutput(); err != nil {\n        return fmt.Errorf(\"module verification failed: %w\\n%s\", err, out)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// On module resolution internal errors, clean cache and retry.\nfunc buildWithRetry() error {\n    err := runBuild()\n    if err != nil && strings.Contains(err.Error(), \"module loader did not resolve\") {\n        // Clean cache and re-resolve\n        exec.Command(\"go\", \"clean\", \"-modcache\").Run()\n        if tidyErr := exec.Command(\"go\", \"mod\", \"tidy\").Run(); tidyErr != nil {\n            return fmt.Errorf(\"go mod tidy failed: %w\", tidyErr)\n        }\n        err = runBuild() // single retry\n    }\n    return err\n}","preventionTips":["Run go mod tidy regularly to keep go.sum consistent.","Commit go.sum to version control.","Update the Go toolchain to the latest patch release.","Run go mod verify in CI to detect cache corruption early.","Pin module versions explicitly in go.mod."],"tags":["go","go-build","modules","import-path","internal-error","module-cache"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}