{"record":{"id":"eae45d1bbd00cf06","repo":"golang/go","slug":"config-importer-not-installed","errorCode":null,"errorMessage":"Config.Importer not installed","messagePattern":"Config\\.Importer not installed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/types2/resolver.go","lineNumber":149,"sourceCode":"\tkey := importKey{path, dir}\n\timp := check.impMap[key]\n\tif imp != nil {\n\t\treturn imp\n\t}\n\n\t// no package yet => import it\n\tif path == \"C\" && (check.conf.FakeImportC || check.conf.go115UsesCgo) {\n\t\tif check.conf.FakeImportC && check.conf.go115UsesCgo {\n\t\t\tcheck.error(pos, BadImportPath, \"cannot use FakeImportC and go115UsesCgo together\")\n\t\t}\n\t\timp = NewPackage(\"C\", \"C\")\n\t\timp.fake = true // package scope is not populated\n\t\timp.cgo = check.conf.go115UsesCgo\n\t} else {\n\t\t// ordinary import\n\t\tvar err error\n\t\tif importer := check.conf.Importer; importer == nil {\n\t\t\terr = fmt.Errorf(\"Config.Importer not installed\")\n\t\t} else if importerFrom, ok := importer.(ImporterFrom); ok {\n\t\t\timp, err = importerFrom.ImportFrom(path, dir, 0)\n\t\t\tif imp == nil && err == nil {\n\t\t\t\terr = fmt.Errorf(\"Config.Importer.ImportFrom(%s, %s, 0) returned nil but no error\", path, dir)\n\t\t\t}\n\t\t} else {\n\t\t\timp, err = importer.Import(path)\n\t\t\tif imp == nil && err == nil {\n\t\t\t\terr = fmt.Errorf(\"Config.Importer.Import(%s) returned nil but no error\", path)\n\t\t\t}\n\t\t}\n\t\t// make sure we have a valid package name\n\t\t// (errors here can only happen through manipulation of packages after creation)\n\t\tif err == nil && imp != nil && (imp.name == \"_\" || imp.name == \"\") {\n\t\t\terr = fmt.Errorf(\"invalid package name: %q\", imp.name)\n\t\t\timp = nil // create fake package below\n\t\t}\n\t\tif err != nil {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/types2/resolver.go#L131-L167","documentation":"The types2 Config.Importer field (exposed as go/types.Config.Importer) provides the import resolution mechanism for the type checker. When the checker encounters an import statement and Config.Importer is nil, this error is returned. Without an importer, the type checker cannot resolve imported packages.","triggerScenarios":"Calling checker.Check() or checker.Files() with a types.Config where Importer is nil, when the source code being checked contains import statements for non-C packages. The error is set on the import, and the type checker continues with a fake package.","commonSituations":"Static analysis tools, linters, or code generators that construct a types.Config without setting the Importer. Forgetting to call importer.Default() or importer.ForCompiler(). Test setups that only check self-contained code but later add imports.","solutions":["Set conf.Importer = importer.Default() before calling Check","For source-level imports: conf.Importer = importer.ForCompiler(fset, \"source\", nil)","Use golang.org/x/tools/go/packages which handles import resolution automatically","If checking code with no imports, this error will not fire — but set the importer anyway for safety"],"exampleFix":"// before\nconf := types.Config{}\n_, err := conf.Check(pkgName, fset, files, &info)\n\n// after\nimport \"go/importer\"\n\nconf := types.Config{Importer: importer.Default()}\n_, err := conf.Check(pkgName, fset, files, &info)","handlingStrategy":"validation","validationCode":"// Ensure Config.Importer is set before type-checking\nimport (\n    \"go/importer\"\n    \"go/types\"\n)\n\nfunc newTypeChecker(fset *token.FileSet) *types.Checker {\n    conf := types.Config{\n        Importer: importer.ForCompiler(fset, \"source\", nil),\n    }\n    return conf.NewChecker(fset)\n}\n\n// Or validate before use:\nfunc validateConfig(conf *types.Config) error {\n    if conf.Importer == nil {\n        return fmt.Errorf(\"types.Config.Importer must be set when checking code with imports\")\n    }\n    return nil\n}","typeGuard":"// Type guard / assertion for Importer capability\nfunc hasImporter(conf *types.Config) bool {\n    return conf != nil && conf.Importer != nil\n}\n\n// Check if the importer supports ImportFrom (newer interface)\nfunc supportsImportFrom(conf *types.Config) bool {\n    _, ok := conf.Importer.(types.ImporterFrom)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Always set Config.Importer = importer.Default() or importer.ForCompiler() before calling Check","Use golang.org/x/tools/go/packages instead of manual Config setup — it handles imports automatically","Add a nil check for Importer as part of your tool's initialization validation","Document that the Config requires an Importer in your tool's API documentation"],"tags":["go-types","go-imports","configuration","api-setup"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}