golang/go · error
can't resolve export %s
Error message
can't resolve export %s
What it means
Thrown by the same types.Importer closure after ImportMap successfully maps an import path to a package path. The exporter then looks up that package path in cfg.PackageFile to find the file holding the dependency's compiled export data. If the package path is absent from PackageFile, no export-data file is available and type-checking cannot proceed. `go list -export` is responsible for recording every transitive dependency's export file here.
Source
Thrown at src/cmd/export/main.go:145
return cfg, nil
}
func makeTypesImporter(cfg *config, fset *token.FileSet) types.Importer {
imports := make(map[string]*types.Package)
imports["unsafe"] = types.Unsafe
return importerFunc(func(importPath string) (*types.Package, error) {
pkgPath, ok := cfg.ImportMap[importPath]
if !ok {
return nil, fmt.Errorf("can't resolve import %s", importPath)
}
// Check for cache hit.
if pkg, ok := imports[pkgPath]; ok && pkg.Complete() {
return pkg, nil
}
// Miss.
cfgPath, ok := cfg.PackageFile[pkgPath]
if !ok {
return nil, fmt.Errorf("can't resolve export %s", pkgPath)
}
f, err := os.Open(cfgPath)
if err != nil {
return nil, err
}
defer f.Close()
return gcexportdata.Read(f, fset, imports, pkgPath)
})
}
type importerFunc func(string) (*types.Package, error)
func (f importerFunc) Import(path string) (*types.Package, error) { return f(path) }
View on GitHub (pinned to b6b368adc5)
Solutions
- Re-run `go list -export` over the full relevant package set so each dependency's export data is built and recorded in PackageFile.
- Build/export dependencies in topological (import) order so each package's deps already have export data.
- Keep -mod/-modfile/vendor/GOFLAGS consistent between list and export.
- Inspect the config: confirm every pkgPath returned by ImportMap has an entry in PackageFile.
Defensive patterns
Strategy: validation
Validate before calling
// Ensure each package path from ImportMap has export data in PackageFile.
for _, pkgPath := range cfg.ImportMap {
if _, ok := cfg.PackageFile[pkgPath]; !ok {
return fmt.Errorf("package %s has no export-data file; export dependencies first", pkgPath)
}
} Prevention
- Run `go list -export` over the full relevant package set so all deps are built.
- Export dependencies before dependents (topological order).
- Keep -mod/-modfile/vendor settings consistent across list and export.
When it happens
Trigger: A package being exported imports a dependency whose export-data file was not recorded in cfg.PackageFile. This occurs when the dependency was not itself exported before this package, when it was filtered out, or when the config was generated for only a subset of the dependency graph.
Common situations: Partial/stale configs; exporting a package before its dependencies; -mod=vendor mismatches where a vendored dep lacks export data; running `go tool export` on a config produced by a narrower `go list -export` invocation.
Related errors
- can't resolve import %s
- can't decode input %s: %v
- no files in package %s
- not a known dependency
- Config.Importer.Import(%s) returned nil but no error
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/e998628916e3cc73.
Report an issue: GitHub.