{"record":{"id":"1c4cc084fb5c1119","repo":"golang/go","slug":"parsing-go-mod-module-declares-its-path-as-s","errorCode":null,"errorMessage":"parsing go.mod:\n\tmodule declares its path as: %s\n\t        but was required as: %s","messagePattern":"parsing go\\.mod:\n\tmodule declares its path as: (.+?)\n\t        but was required as: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/modfile.go","lineNumber":638,"sourceCode":"\t\t// matching module paths. Anything goes.\n\t\t//\n\t\t// TODO(bcmills): Remove this special-case, update tests, and add a\n\t\t// release note.\n\t} else {\n\t\tif summary.module.Path == \"\" {\n\t\t\treturn nil, module.VersionError(actual, errors.New(\"parsing go.mod: missing module line\"))\n\t\t}\n\n\t\t// In theory we should only allow mpath to be unequal to m.Path here if the\n\t\t// version that we fetched lacks an explicit go.mod file: if the go.mod file\n\t\t// is explicit, then it should match exactly (to ensure that imports of other\n\t\t// packages within the module are interpreted correctly). Unfortunately, we\n\t\t// can't determine that information from the module proxy protocol: we'll have\n\t\t// to leave that validation for when we load actual packages from within the\n\t\t// module.\n\t\tif mpath := summary.module.Path; mpath != m.Path && mpath != actual.Path {\n\t\t\treturn nil, module.VersionError(actual,\n\t\t\t\tfmt.Errorf(\"parsing go.mod:\\n\"+\n\t\t\t\t\t\"\\tmodule declares its path as: %s\\n\"+\n\t\t\t\t\t\"\\t        but was required as: %s\", mpath, m.Path))\n\t\t}\n\t}\n\n\tfor _, mainModule := range ld.MainModules.Versions() {\n\t\tif index := ld.MainModules.Index(mainModule); index != nil && len(index.exclude) > 0 {\n\t\t\t// Drop any requirements on excluded versions.\n\t\t\t// Don't modify the cached summary though, since we might need the raw\n\t\t\t// summary separately.\n\t\t\thaveExcludedReqs := false\n\t\t\tfor _, r := range summary.require {\n\t\t\t\tif index.exclude[r] {\n\t\t\t\t\thaveExcludedReqs = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif haveExcludedReqs {","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/modfile.go#L620-L656","documentation":"Returned while building a module graph summary (modfile.go:638) when the module directive inside a fetched dependency's go.mod declares a different path than the path it was required under, and also different from any replacement target. The toolchain refuses to use a module whose self-declared identity disagrees with how it was imported, because import resolution within that module would be ambiguous.","triggerScenarios":"A go.mod fetched for path A declares 'module B'; the requirement pointed at A but the downloaded artifact is actually B; a misconfigured module proxy or fork served the wrong go.mod; a replace directive targets a directory whose go.mod names a different module.","commonSituations":"A dependency was renamed/moved but an old require still references the former path; a fork served under the original path; a vendored or replaced local module whose go.mod module line was not updated after a rename.","solutions":["Update the require/replace to the path the module actually declares (the value shown as 'module declares its path as').","If using a replace to a local directory, fix the module directive in that directory's go.mod to match the required path.","Clear the corrupted entry from the module cache and re-download: 'go clean -modcache && go mod download'.","Report to the module author if a published version genuinely ships the wrong module path."],"exampleFix":"// before\ngo.mod requires: require example.com/old v1.0.0\n// fetched go.mod says: module example.com/new\n// error: parsing go.mod: module declares its path as: example.com/new\n//                      but was required as: example.com/old\n\n// after\nrequire example.com/new v1.0.0","handlingStrategy":"validation","validationCode":"// When using a replace target, verify its go.mod module line matches the required path:\n//   repMod := exec.Command(\"go\", \"mod\", \"edit\", \"-print\").run-in-replace-dir\n//   require repMod == requiredPath before committing the replace directive.","typeGuard":"func modulePathMatchesRequired(f *modfile.File, required string) bool {\n    return f != nil && f.Module != nil && (f.Module.Mod.Path == required)\n}","tryCatchPattern":null,"preventionTips":["After renaming a module, update every require and the module's own module directive in lockstep.","For local replacements, keep the replaced directory's module line equal to the required path.","Run 'go list -m all' in CI to surface path mismatches early."],"tags":["go-modules","module-graph","go-mod","path-mismatch","replace"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}