golang/go · error
no files in package %s
Error message
no files in package %s
What it means
Thrown by `go tool export` (an internal helper driven by `go list -export`) inside readConfig, right after JSON-decoding the unit.cfg file. The config struct's GoFiles slice is empty, meaning the package has no Go source files to parse and type-check, so the exporter refuses to proceed and names cfg.ImportPath. The export tool is not intended to be invoked by end users; `go list -export` generates its config.
Source
Thrown at src/cmd/export/main.go:125
}
if err := gcexportdata.Write(f, fset, pkg); err != nil {
f.Close() // ignore error
return err
}
return f.Close()
}
func readConfig(filename string) (*config, error) {
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
cfg := new(config)
if err := json.Unmarshal(data, cfg); err != nil {
return nil, fmt.Errorf("can't decode input %s: %v", filename, err)
}
if len(cfg.GoFiles) == 0 {
return nil, fmt.Errorf("no files in package %s", cfg.ImportPath)
}
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]View on GitHub (pinned to b6b368adc5)
Solutions
- Do not call `go tool export` directly; run `go list -export <pkg>` which generates a correct config including GoFiles.
- If you must supply a config, ensure cfg.GoFiles contains at least one absolute path to a .go file that belongs to the package.
- Confirm the package actually has Go source files for your GOOS/GOARCH (run `go list -f '{{.GoFiles}}' <pkg>`).
- Re-run `go list -export` after any source/build-context change to regenerate the config.
Defensive patterns
Strategy: validation
Validate before calling
// Before passing a config to export, verify it has source files.
if len(cfg.GoFiles) == 0 {
return fmt.Errorf("config for %s has no Go files; regenerate via 'go list -export'", cfg.ImportPath)
} Prevention
- Prefer `go list -export <pkg>` over invoking `go tool export` directly.
- Treat unit.cfg files as generated artifacts; regenerate after source or build-context changes.
- Confirm packages have Go source for the target GOOS/GOARCH before exporting.
When it happens
Trigger: A unit.cfg with a GoFiles array of length zero is passed to `go tool export`. This occurs when the package being exported contains no .go files for the active build context (e.g. an assembly-only package, or all .go files excluded by build tags), or when a hand-written config omits GoFiles.
Common situations: Running `go tool export unit.cfg` directly on a hand-authored config; building a package composed solely of .s assembly or cgo .c/.h files with no .go files; GOOS/GOARCH build constraints filtering out every Go file; a stale or corrupted config produced by an interrupted `go list -export`.
Related errors
- can't decode input %s: %v
- can't resolve import %s
- can't resolve export %s
- cannot run go list: %v %s
- decoding go list json: %v
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/58de8398fd91ed57.
Report an issue: GitHub.