Handling +incompatible Module Versions
Understand the +incompatible suffix in Go module versions. Learn why some modules have this suffix and how to work with pre-module Go packages that did not follow semantic import versioning.
Detailed Explanation
The +incompatible Suffix
Some module versions in go.mod have a +incompatible suffix:
require (
github.com/docker/docker v24.0.7+incompatible
github.com/docker/go-connections v0.4.0+incompatible
)
What It Means
The +incompatible suffix indicates that a module:
- Has a major version v2 or higher in its git tags
- Does not have a go.mod file (or its go.mod does not use the /vN suffix)
- Was created before Go modules became standard
Why It Exists
Before Go modules (pre-Go 1.11), Go packages did not follow the import compatibility rule. Many popular packages (like Docker) tagged v2, v3, etc. without using the /vN path suffix. When Go modules were introduced, these existing tags needed to work somehow.
The Compatibility Bridge
Go treats +incompatible versions as a special case:
- The module path does NOT include
/vN(e.g., justgithub.com/docker/docker) - The version is
vN.X.Y+incompatible(e.g.,v24.0.7+incompatible) - Go knows this module predates the import compatibility rule
When You See It
github.com/lib/pq v1.10.9 // Normal: v1.x, no suffix
github.com/docker/docker v24.0.7+incompatible // +incompatible: v24 but no /v24 suffix
github.com/example/mod/v2 v2.3.0 // Normal: v2 with /v2 suffix
Working With +incompatible Modules
- You cannot remove the suffix — it is determined by the module author's repository
go getadds it automatically- The formatter preserves the suffix as-is
- Functionally, it works like any other dependency
Migration Path
When a module author adds a proper go.mod with the /vN suffix, future versions will not need +incompatible. Users migrating will:
- Change the import path to include /vN
- Update go.mod to use the new module path
- The +incompatible suffix disappears for the new version
Common +incompatible Modules
Many Docker ecosystem packages use +incompatible because they predate Go modules and have high major version numbers.
Use Case
Encountering +incompatible versions is common when working with the Docker SDK, certain database drivers, and other pre-modules Go packages. Understanding this suffix helps developers avoid confusion when reading go.mod files and ensures they do not mistakenly try to add /vN suffixes to these import paths. The formatter handles +incompatible versions correctly in sorting and alignment.