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: go.work lists module github.com/org/app at both
./app and ./services/appCommon 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.
go work edit -dropuse ./services/app
go work syncRegenerate go.work.sum
Sync the workspace so go.work.sum records hashes for the current set of used modules.
go work sync
git add go.work go.work.sumHow to prevent it
- List each module once in
go.work; avoid overlappingusepaths. - Run
go work syncafter changing the set of workspace modules. - Decide whether
go.workis committed or local-only and apply it consistently.