golang/go · error

importcfg:%d: invalid packagefile: syntax is "packagefile pa

Error message

importcfg:%d: invalid packagefile: syntax is "packagefile path=filename": %s

What it means

The gccgo importcfg parser handles `packagefile path=filename` directives. After splitting args on '=' with strings.Cut, both the path (before) and filename (after) must be non-empty. If either side is empty, this fires with the line number and offending line. Importcfg files are generated by the go command, so a malformed directive usually means a hand-edited or corrupted file.

Source

Thrown at src/cmd/go/internal/work/gccgo.go:167

		if line == "" {
			continue
		}
		if line == "" || strings.HasPrefix(line, "#") {
			continue
		}
		var verb, args string
		if i := strings.Index(line, " "); i < 0 {
			verb = line
		} else {
			verb, args = line[:i], strings.TrimSpace(line[i+1:])
		}
		before, after, _ := strings.Cut(args, "=")
		switch verb {
		default:
			base.Fatalf("importcfg:%d: unknown directive %q", lineNum, verb)
		case "packagefile":
			if before == "" || after == "" {
				return fmt.Errorf(`importcfg:%d: invalid packagefile: syntax is "packagefile path=filename": %s`, lineNum, line)
			}
			archive := gccgoArchive(root, before)
			if err := sh.Mkdir(filepath.Dir(archive)); err != nil {
				return err
			}
			if err := sh.Symlink(after, archive); err != nil {
				return err
			}
		case "importmap":
			if before == "" || after == "" {
				return fmt.Errorf(`importcfg:%d: invalid importmap: syntax is "importmap old=new": %s`, lineNum, line)
			}
			beforeA := gccgoArchive(root, before)
			afterA := gccgoArchive(root, after)
			if err := sh.Mkdir(filepath.Dir(beforeA)); err != nil {
				return err
			}
			if err := sh.Mkdir(filepath.Dir(afterA)); err != nil {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Do not hand-edit importcfg files; let the go command generate them
  2. Rebuild from scratch: `go clean -cache && go build`
  3. If using gccgo, confirm you are on a compatible gccgo/go version
Defensive patterns

Strategy: validation

Validate before calling

// Validate an importcfg packagefile line before passing it to gccgo
func validPackagefileLine(line string) bool {
    _, after, ok := strings.Cut(line, " ")
    if !ok { return false }
    before, after, ok := strings.Cut(after, "=")
    return ok && before != "" && after != ""
}

Prevention

When it happens

Trigger: Fires in the gccgo importcfg reader's `case "packagefile"` branch when before == "" or after == "" after strings.Cut(args, "=").

Common situations: A hand-edited or truncated importcfg file, a toolchain bug generating malformed output, or a file transfer that corrupted line endings.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/3c0dbc7cbb083431. Report an issue: GitHub.