{"record":{"id":"144b904cc7146141","repo":"golang/go","slug":"can-t-resolve-import-s","errorCode":null,"errorMessage":"can't resolve import %s","messagePattern":"can't resolve import (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/export/main.go","lineNumber":136,"sourceCode":"\t\treturn nil, err\n\t}\n\tcfg := new(config)\n\tif err := json.Unmarshal(data, cfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"can't decode input %s: %v\", filename, err)\n\t}\n\tif len(cfg.GoFiles) == 0 {\n\t\treturn nil, fmt.Errorf(\"no files in package %s\", cfg.ImportPath)\n\t}\n\treturn cfg, nil\n}\n\nfunc makeTypesImporter(cfg *config, fset *token.FileSet) types.Importer {\n\timports := make(map[string]*types.Package)\n\timports[\"unsafe\"] = types.Unsafe\n\treturn importerFunc(func(importPath string) (*types.Package, error) {\n\t\tpkgPath, ok := cfg.ImportMap[importPath]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"can't resolve import %s\", importPath)\n\t\t}\n\t\t// Check for cache hit.\n\t\tif pkg, ok := imports[pkgPath]; ok && pkg.Complete() {\n\t\t\treturn pkg, nil\n\t\t}\n\t\t// Miss.\n\t\tcfgPath, ok := cfg.PackageFile[pkgPath]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"can't resolve export %s\", pkgPath)\n\t\t}\n\t\tf, err := os.Open(cfgPath)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdefer f.Close()\n\t\treturn gcexportdata.Read(f, fset, imports, pkgPath)\n\t})\n}","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/export/main.go#L118-L154","documentation":"Thrown by the custom types.Importer closure inside makeTypesImporter during type-checking. For every import in the package's source, the exporter must translate the import path to a package path via cfg.ImportMap. If the import path is not a key in ImportMap, the importer cannot resolve it and fails. ImportMap is populated by `go list -export` and must list every import the package references.","triggerScenarios":"A source file imports a path that does not appear as a key in cfg.ImportMap. This happens when the config is stale relative to the source (a new import was added after the config was generated), or when a cgo/conditional import is active during type-checking but was not captured by `go list -export`.","commonSituations":"Editing source to add a new import then reusing a previously generated .cfg; build tags/GOOS/GOARCH differing between the `go list` run and the export run; manually trimming ImportMap; vendoring changes that rename import paths.","solutions":["Regenerate the export config with a fresh `go list -export` so ImportMap reflects all current imports.","Never hand-edit generated .cfg files; treat them as build artifacts.","Keep GOOS/GOARCH/GOFLAGS/tags identical between the `go list -export` step and any later export step.","Verify ImportMap coverage: `go list -export -json <pkg>` and check ImportMap contains each imported path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure every import referenced by the package is in ImportMap.\nfor _, f := range cfg.GoFiles {\n    // (parse f's imports, then:)\n    for _, imp := range importsOf(f) {\n        if _, ok := cfg.ImportMap[imp]; !ok {\n            return fmt.Errorf(\"import %s missing from ImportMap; rerun go list -export\", imp)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Regenerate the export config with `go list -export` after adding or removing imports.","Keep GOOS/GOARCH/GOFLAGS/tags identical between list and export.","Never hand-edit generated .cfg files."],"tags":["go-toolchain","export","importer","go-list","types","build-constraints"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}