golang/go · error
import path %q is reserved and cannot be used
Error message
import path %q is reserved and cannot be used
What it means
Returned by checkImportPath when the path is one of the compiler-reserved import paths ("go" or "type"). These prefixes are reserved because the linker uses magic symbol prefixes "go:" and "type:", and allowing them as import paths would collide with generated internal symbols.
Source
Thrown at src/cmd/compile/internal/noder/import.go:313
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)
case r == '\\':
return fmt.Errorf("import path contains backslash; use slash: %q", path)
case !allowSpace && unicode.IsSpace(r):
return fmt.Errorf("import path contains space character: %q", path)
case strings.ContainsRune("!\"#$%&'()*,:;<=>?[]^`{|}", r):
return fmt.Errorf("import path contains invalid character '%c': %q", r, path)
}
}
View on GitHub (pinned to b6b368adc5)
Solutions
- Rename the package/import path so the final element is not "go" or "type" (e.g. goutils, typeutil).
- If you genuinely need a short path, use a module subpath like example.com/go/internal/....
- Re-run goimports to let it resolve to a non-reserved path.
Example fix
// before import "go" // after import "example.com/myproj/goutils"
Defensive patterns
Strategy: validation
Validate before calling
import "cmd/compile/internal/base"
if base.ReservedImports[path] {
return fmt.Errorf("rename package; %q is reserved", path)
} Type guard
// isReservedImportPath reports whether path is one of the compiler-reserved paths.
func isReservedImportPath(path string) bool {
return path == "go" || path == "type"
} Prevention
- Never name a module's final path element 'go' or 'type'.
- Add a linter rule rejecting reserved path elements.
When it happens
Trigger: A Go source file imports "go" or "type"; the loop over base.ReservedImports matches and the error reports the offending path.
Common situations: Naming a local module/package "go" or "type" and importing it; auto-generated import insertion picking a colliding short path; refactoring a package into a path whose final element is reserved.
Related errors
- import path contains invalid UTF-8 sequence: %q
- import path contains control character: %q
- import path contains backslash; use slash: %q
- import path contains space character: %q
- import path contains invalid character '%c': %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/1e7b79435285f9fe.
Report an issue: GitHub.