Skip to content
Latchkey

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.0

Common 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

  1. Decide which module should own the path and remove the other from go.mod.
  2. Run go mod tidy to settle the graph.
shell
go mod edit -droprequire example.com/lib/util
go mod tidy

Pin with a replace

  1. 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.0

How 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →