go
module_error
ai_generated
partial
go: ambiguous import: found package X in multiple modules: github.com/foo/bar and github.com/baz/bar
ID: go/go-mod-tidy-ambiguous-import
82%Fix Rate
87%Confidence
1Evidence
2024-05-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| go1.21 | active | — | — | — |
| go1.22 | active | — | — | — |
Root Cause
Two different modules provide the same import path, causing ambiguity in the module resolution.
generic中文
两个不同的模块提供了相同的导入路径,导致模块解析歧义。
Official Documentation
https://go.dev/ref/mod#go-mod-file-requireWorkarounds
-
90% success Use a replace directive in go.mod to force one module: replace github.com/foo/bar => github.com/foo/bar v1.2.3
Use a replace directive in go.mod to force one module: replace github.com/foo/bar => github.com/foo/bar v1.2.3
-
75% success Rename one of the conflicting packages or use a different import path by vendoring.
Rename one of the conflicting packages or use a different import path by vendoring.
中文步骤
在 go.mod 中使用 replace 指令强制指定一个模块:replace github.com/foo/bar => github.com/foo/bar v1.2.3
重命名冲突的包之一,或通过 vendor 使用不同的导入路径。
Dead Ends
Common approaches that don't work:
-
Running go mod tidy repeatedly hoping it resolves
95% fail
go mod tidy cannot resolve ambiguity; it requires manual intervention to specify which module to use.
-
Deleting go.sum and re-running go mod download
80% fail
Deleting go.sum doesn't fix the import path conflict; it only removes checksums.