golang/go · error

import path is empty

Error message

import path is empty

What it means

Thrown by checkImportPath when the import path is the empty string. This is the first validation in checkImportPath and rejects degenerate imports before any further character-level checks run.

Source

Thrown at src/cmd/compile/internal/noder/import.go:304

// the exportdata.
func addFingerprint(path string, data string) error {
	var fingerprint goobj.FingerprintType

	pos := len(data) - len(fingerprint)
	if pos < 0 {
		return fmt.Errorf("missing linker fingerprint in exportdata, but found %q", data)
	}
	buf := []byte(data[pos:])

	copy(fingerprint[:], buf)
	base.Ctxt.AddImport(path, fingerprint)

	return nil
}

func checkImportPath(path string, allowSpace bool) error {
	if path == "" {
		return errors.New("import path is empty")
	}

	if strings.Contains(path, "\x00") {
		return errors.New("import path contains NUL")
	}

	for ri := range base.ReservedImports {
		if path == ri {
			return fmt.Errorf("import path %q is reserved and cannot be used", path)
		}
	}

	for _, r := range path {
		switch {
		case r == utf8.RuneError:
			return fmt.Errorf("import path contains invalid UTF-8 sequence: %q", path)
		case r < 0x20 || r == 0x7f:
			return fmt.Errorf("import path contains control character: %q", path)

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Ensure the import declaration has a real, non-empty path.
  2. Audit code generators / templating that interpolate import paths.
  3. Check import-map configuration for empty keys or values.

Example fix

// before
import ""
// after
import "fmt"
Defensive patterns

Strategy: validation

Validate before calling

// Reject empty import paths before passing them to the compiler.
func nonEmptyImport(p string) bool { return p != "" }

Prevention

When it happens

Trigger: Code or tooling that produces an empty import path string and passes it to the compiler/import resolver, e.g. `import ""` in generated or hand-edited source, or an import map keyed by "".

Common situations: Buggy code generation that emits an empty import; string formatting bug that drops the path; an import map that maps something to/from an empty key; accidental blank import of an empty string.

Related errors


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