Skip to content
Latchkey

Go "go.work lists ... at both" - Fix Duplicate use Directives in CI

A go.work file may list each module exactly once. When two use directives resolve to the same module path - usually a use . plus a use ./sub that overlap, or a copy-paste - Go refuses the workspace with a duplicate-module error.

What this error means

A workspace build fails with go.work lists module <path> at both <dirA> and <dirB>, or with a go.work.sum mismatch when the recorded sums no longer cover the modules the workspace uses. It is deterministic and tied to the go.work contents, not the network.

go output
go: go.work lists module github.com/org/app at both
	./app and ./services/app

Common causes

Two use directives resolving to one module

A use ./app and a use ./services/app (a symlink or copy of the same module) both declare github.com/org/app, so the workspace has the module listed twice.

go.work.sum out of sync with the used modules

After adding or moving a workspace module, go.work.sum was not regenerated, so its recorded hashes no longer match the modules the workspace pulls in.

How to fix it

Remove the duplicate use directive

Keep exactly one use entry per module and drop the overlapping one.

Terminal
go work edit -dropuse ./services/app
go work sync

Regenerate go.work.sum

Sync the workspace so go.work.sum records hashes for the current set of used modules.

Terminal
go work sync
git add go.work go.work.sum

How to prevent it

  • List each module once in go.work; avoid overlapping use paths.
  • Run go work sync after changing the set of workspace modules.
  • Decide whether go.work is committed or local-only and apply it consistently.

Related guides

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