Go "ambiguous import: found in multiple modules" - Fix in CI
Go must resolve each import to exactly one module. When a path lives in two modules at once (often after a module split or a vanity-path move), Go cannot choose and reports the ambiguity.
What this error means
A build fails with ambiguous import: found package X in multiple modules. Two required modules both claim the same import path.
go
ambiguous import: found package example.com/lib/util in multiple modules:
example.com/lib v1.4.0
example.com/lib/util v0.2.0Common causes
Package moved to its own module
A subpackage was promoted to a standalone module, so both the old parent and the new module provide the path.
Two required versions overlap
The graph requires two modules whose paths overlap for one package.
How to fix it
Drop the obsolete requirement
- Decide which module should own the path and remove the other from go.mod.
- Run go mod tidy to settle the graph.
shell
go mod edit -droprequire example.com/lib/util
go mod tidyPin with a replace
- If both are needed transitively, pin one version with a replace to remove the overlap.
go.mod
replace example.com/lib/util => example.com/lib/util v0.2.0How to prevent it
- After a module split, remove the now-obsolete requirement.
- Run go mod tidy and commit when the dependency set changes.
- Avoid importing the same path from two overlapping modules.
Related guides
Go "cannot find package" (vendor stale) - Fix in CIFix Go "cannot find package" in CI when the vendor directory is stale - go.mod added a dependency that was ne…
Go "directory prefix does not contain main module" - Fix in CIFix Go "directory prefix X does not contain main module or its selected dependencies" in CI - the command ran…
Go "go.mod inconsistent" with -mod=readonly - Fix in CIFix Go failing under -mod=readonly because go.mod/go.sum are out of date in CI - run go mod tidy locally and…