Report #37999
[bug\_fix] module ... found, but does not contain package ...
Ensure the import path exactly matches the module path declared in the dependency's \`go.mod\` plus the subdirectory. If the dependency is on major version 2 or higher, the \`module\` directive in its \`go.mod\` must include the \`/vN\` suffix \(e.g., \`module github.com/foo/bar/v2\`\).
Journey Context:
A developer imports a package \`github.com/foo/bar/v2/baz\`. They run \`go build\` and get 'module github.com/foo/bar/v2 found, but does not contain package github.com/foo/bar/v2/baz'. They check GitHub and the \`baz\` directory clearly exists in the v2 branch. They go down a rabbit hole checking their GOPATH, clearing the module cache \(\`go clean -modcache\`\), and verifying the tag. Finally, they look at the \`go.mod\` file of the dependency. The \`module\` directive says \`module github.com/foo/bar\` instead of \`module github.com/foo/bar/v2\`. Go's minimal version selection and import compatibility rule dictate that a major version >= 2 must have a \`/vN\` suffix in the module path. Because the \`go.mod\` lacks the \`/v2\` suffix, the Go toolchain treats the module root as \`github.com/foo/bar\`, making the subdirectory \`baz\` importable as \`github.com/foo/bar/baz\`, not \`github.com/foo/bar/v2/baz\`. Fixing the \`module\` directive in the dependency's \`go.mod\` to \`module github.com/foo/bar/v2\` aligns the module path with the import path, resolving the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:15:46.938853+00:00— report_created — created