Report #100571
[bug\_fix] go: module path check failed: module declared as "github.com/foo/bar" but imported as "github.com/foo/bar/v2/pkg" \(or mismatch between go.mod module directive and repository path\)
Edit go.mod so the module directive exactly matches the canonical import path prefix under which the module is consumed. If the repository moved or the module was renamed, update all imports and the module path to match, then run "go mod tidy". Do not keep a stale module statement.
Journey Context:
You clone a service or copy a package into a new repo and run "go build ./...". The compiler stops with an error about the module path not matching the import path, often after a teammate renamed the repo or you ran "go mod init example.com/old" without thinking. You grep the source and every import uses the new path, so the source looks consistent. The rabbit-hole is checking GOPATH, GOMODCACHE, and vendor/ because the error sounds like a fetch issue. Eventually you open go.mod and see "module example.com/old" while the imports say "example.com/new/pkg". The go command uses the module statement as the root import path for all packages in the tree, so when a package is imported via a different prefix Go sees a foreign module and refuses the build. Correcting the module directive makes the local packages addressable under the same prefix that the imports expect, and go mod tidy cleans up the requirement graph.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T04:44:09.643220+00:00— report_created — created