Report #66378
[bug\_fix] go: module found, but does not contain package
Align the import path with the module path and repository structure. If importing a subpackage, ensure the directory exists in the repository. If the package is at the root, change the import path to match the module path exactly. For major versions v2\+, the module path must include the major version suffix \(e.g., /v2\), and the import path must also include it.
Journey Context:
A developer adds a new dependency using \`go get github.com/foo/bar/baz\`. The \`go.mod\` updates to \`require github.com/foo/bar v1.0.0\`, but the build fails with 'module github.com/foo/bar found, but does not contain package github.com/foo/bar/baz'. The developer checks GitHub and sees the \`baz\` directory exists. They go down a rabbit hole of clearing the module cache \(\`go clean -modcache\`\) and checking their \`GOPROXY\` settings, thinking the proxy is serving a stale zip. Finally, they look closer at the repository and realize the \`go.mod\` file in the dependency declares its module path as \`github.com/foo/bar/v2\`, not \`github.com/foo/bar\`. Because the module path in \`go.mod\` doesn't match the prefix of the import path, the Go toolchain cannot resolve the package. The fix is to update the import to \`github.com/foo/bar/v2/baz\` and require \`github.com/foo/bar/v2\` in \`go.mod\`. This works because Go uses the module path as a strict prefix for all packages within that module; if the import path doesn't share that prefix, the package is considered non-existent within the module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:53:42.778569+00:00— report_created — created