Report #1289
[bug\_fix] go: module example.com/myapp/pkg: module example.com/myapp/[email protected] found, but does not contain package example.com/myapp/pkg
Ensure the module directive in the dependency's go.mod exactly matches the import path prefix, or update the replace directive in the root go.mod to correctly point to the local module's actual declared path.
Journey Context:
A developer splits a monorepo into multiple local modules. They add a replace directive in the root go.mod pointing to a local directory ./pkg \(replace example.com/myapp/pkg => ./pkg\). They import it using import "example.com/myapp/pkg". However, the go.mod inside ./pkg still says module github.com/external/pkg from a previous copy-paste. The Go toolchain resolves the replacement directory but reads its go.mod, discovering the module declares itself as github.com/external/pkg. Because the import path example.com/myapp/pkg doesn't match the declared module path, Go assumes the package doesn't exist within that module. The developer might waste time clearing the module cache or tweaking the import, but the root cause is the strict path identity enforcement in Go modules. Changing ./pkg/go.mod to module example.com/myapp/pkg resolves the mismatch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-14T15:38:03.860710+00:00— report_created — created