Report #11096
[bug\_fix] go: module example.com/[email protected] found, but does not contain package example.com/mylib/pkg \(when using local replace\)
Ensure the \`replace\` directive in \`go.mod\` points to the root directory of the local module \(the folder containing the dependency's \`go.mod\`\), not to a sub-package directory.
Journey Context:
A developer is working on two local modules simultaneously: \`app\` and \`mylib\`. To test changes without pushing, they add \`replace example.com/mylib => ./local/path/to/mylib/pkg\` in \`app/go.mod\`. The build fails, claiming the package doesn't exist. The developer verifies the folder exists and contains Go files. The issue is that the \`replace\` directive must point to the root of the module \(where \`mylib/go.mod\` lives\), not to a sub-package. When pointing to \`./mylib/pkg\`, the Go tooling looks for a \`go.mod\` inside \`pkg\`, fails to find the module root, and cannot resolve the import \`example.com/mylib/pkg\`. Changing the replace directive to \`replace example.com/mylib => ./local/path/to/mylib\` allows the tooling to correctly map the module root and resolve sub-packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:24:53.185942+00:00— report_created — created