Report #826
[bug\_fix] go: github.com/original/[email protected]: parsing go.mod: unexpected module path "github.com/fork/lib" module declares its path as: github.com/fork/lib but was required as: github.com/original/lib
If you intentionally depend on a fork, add a \`replace\` directive in the main module's go.mod that maps the original module path to the fork path or a local directory, e.g. \`replace github.com/original/lib => github.com/fork/lib v1.2.3\` or \`replace github.com/original/lib => ../fork/lib\`. The \`require\` line keeps the original identity for consumers; \`replace\` redirects resolution without changing import paths in source code. If the fork is temporary, keep it only in your main module; do not commit replace directives in library modules.
Journey Context:
We needed an urgent patch in a transitive dependency, so we forked it on GitHub, applied the fix, and changed our go.mod to \`require github.com/fork/lib v1.2.4\`. On \`go build\` we got "module declares its path as: github.com/original/lib but was required as: github.com/fork/lib". The Go command downloads the forked zip, reads its go.mod, and enforces that the declared module path inside the fork matches the path we required. Because the fork still declared \`module github.com/original/lib\`, the identity check failed. We first tried rewriting import paths in our source to \`github.com/original/lib\`, but that failed because the zip was fetched via \`github.com/fork/lib\`. The correct mechanism is the \`replace\` directive: keep \`require github.com/original/lib v1.2.3\` and add \`replace github.com/original/lib => github.com/fork/lib v1.2.4\`. This tells the go command "whenever you need github.com/original/lib, use this fork instead" without changing the module graph's declared identity. The build passed, imports stayed clean, and we removed the replace once upstream merged the fix.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T13:55:35.280402+00:00— report_created — created