Go "ambiguous import: found package in multiple modules" - Fix in CI
Two different modules in your graph both claim to provide the same import path. Go cannot decide which to use, so it refuses with ambiguous import instead of guessing.
What this error means
A build fails with ambiguous import: found package <path> in multiple modules, listing the two modules. It commonly happens when both an old non-suffixed module and its /v2+ successor end up required at once.
ambiguous import: found package github.com/org/lib/foo in multiple modules:
github.com/org/lib v1.5.0 (/root/go/pkg/mod/...)
github.com/org/lib/v2 v2.1.0 (/root/go/pkg/mod/...)Common causes
Both a module and its /vN successor are required
A transitive dependency still requires the old path while your code (or another dep) uses the /v2 path, so the same package exists under two module identities.
A fork and the original both provide the path
A replace or an extra require brings in a fork that declares the same import path as the upstream module.
How to fix it
Consolidate on a single major version
- Run
go mod graphto see who requires each module version. - Upgrade or downgrade dependencies so only one of the conflicting module paths remains.
- Migrate your own imports to the chosen path, then
go mod tidy.
Drop the redundant requirement
If one module is only present transitively and unused, remove the dependency that drags it in or bump it to a release that no longer requires the duplicate.
go mod why github.com/org/lib
go mod tidyHow to prevent it
- Keep dependencies on one major version of each module.
- Audit
go mod graphafter upgrades for duplicate module paths. - Avoid replaces that re-provide an existing import path.