{"record":{"id":"a64eb27dc9c58f2f","repo":"golang/go","slug":"s-in-s-the-go-mod-file-for-the-module-provid","errorCode":null,"errorMessage":"%s (in %s):\n\tThe go.mod file for the module providing named packages contains one or\n\tmore %s directives. It must not contain directives that would cause\n\tit to be interpreted differently than if it were the main module.","messagePattern":"(.+?) \\(in (.+?)\\):\n\tThe go\\.mod file for the module providing named packages contains one or\n\tmore (.+?) directives\\. It must not contain directives that would cause\n\tit to be interpreted differently than if it were the main module\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":3459,"sourceCode":"\t\treturn nil, fmt.Errorf(\"%s: %w\", args[0], err)\n\t}\n\tif deprecation != \"\" {\n\t\tfmt.Fprintf(os.Stderr, \"go: module %s is deprecated: %s\\n\", rootMod.Path, modload.ShortMessage(deprecation, \"\"))\n\t}\n\tdata, err := ld.Fetcher().GoMod(ctx, rootMod.Path, rootMod.Version)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", args[0], err)\n\t}\n\tf, err := modfile.Parse(\"go.mod\", data, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s (in %s): %w\", args[0], rootMod, err)\n\t}\n\tdirectiveFmt := \"%s (in %s):\\n\" +\n\t\t\"\\tThe go.mod file for the module providing named packages contains one or\\n\" +\n\t\t\"\\tmore %s directives. It must not contain directives that would cause\\n\" +\n\t\t\"\\tit to be interpreted differently than if it were the main module.\"\n\tif len(f.Replace) > 0 {\n\t\treturn nil, fmt.Errorf(directiveFmt, args[0], rootMod, \"replace\")\n\t}\n\tif len(f.Exclude) > 0 {\n\t\treturn nil, fmt.Errorf(directiveFmt, args[0], rootMod, \"exclude\")\n\t}\n\n\t// Since we are in NoRoot mode, the build list initially contains only\n\t// the dummy command-line-arguments module. Add a requirement on the\n\t// module that provides the packages named on the command line.\n\tif _, err := modload.EditBuildList(ld, ctx, nil, []module.Version{rootMod}); err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %w\", args[0], err)\n\t}\n\n\t// Load packages for all arguments.\n\tpkgs := PackagesAndErrors(ld, ctx, opts, patterns)\n\n\t// Check that named packages are all provided by the same module.\n\tfor _, pkg := range pkgs {\n\t\tvar pkgErr error","sourceCodeStart":3441,"sourceCodeEnd":3477,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L3441-L3477","documentation":"The package@version install workflow runs in NoRoot mode (no main module). For safety it refuses modules whose go.mod contains `replace` directives, because replaces would change dependency resolution and make the result differ from how the module behaves as a main module. Only `replace`-free go.mod files are accepted.","triggerScenarios":"`go install example.com/pkg@v1.0.0` where example.com/pkg's published go.mod contains one or more `replace` directives.","commonSituations":"Module author accidentally left local `replace` directives in a tagged release; the module uses replaces internally for development.","solutions":["Choose a version of the module that does not contain replace directives (check `go list -m -json -versions` or the VCS tags).","Clone the module locally and `go install` from within the checkout where it is the main module.","Report to the maintainer that a released tag carries replace directives."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Inspect go.mod for replace directives before installing.\nfunc hasReplaceDirective(mod, ver string) (bool, error) {\n    out, err := exec.Command(\"go\", \"mod\", \"download\", \"-json\", mod+\"@\"+ver).Output()\n    if err != nil { return false, err }\n    var info struct{ GoMod string }\n    if err := json.Unmarshal(out, &info); err != nil { return false, err }\n    data, err := os.ReadFile(info.GoMod)\n    if err != nil { return false, err }\n    return bytes.Contains(data, []byte(\"replace \")), nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-validate module versions you depend on for replace/exclude directives.","Maintain an allowlist of vetted versions for automated installs.","Prefer modules whose releases are tested without local replaces."],"tags":["go-toolchain","go-mod","replace-directive","install"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}