{"record":{"id":"3a51096f1a14fa75","repo":"golang/go","slug":"package-s-provided-by-module-s-s-all-packages","errorCode":null,"errorMessage":"package %s provided by module %s@%s\n\tAll packages must be provided by the same module (%s).","messagePattern":"package (.+?) provided by module (.+?)@(.+?)\n\tAll packages must be provided by the same module \\((.+?)\\)\\.","errorType":"exception","errorClass":"PackageError","httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/load/pkg.go","lineNumber":3483,"sourceCode":"\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\n\t\tif pkg.Module == nil {\n\t\t\t// Packages in std, cmd, and their vendored dependencies\n\t\t\t// don't have this field set.\n\t\t\tpkgErr = fmt.Errorf(\"package %s not provided by module %s\", pkg.ImportPath, rootMod)\n\t\t} else if pkg.Module.Path != rootMod.Path || pkg.Module.Version != rootMod.Version {\n\t\t\tpkgErr = fmt.Errorf(\"package %s provided by module %s@%s\\n\\tAll packages must be provided by the same module (%s).\", pkg.ImportPath, pkg.Module.Path, pkg.Module.Version, rootMod)\n\t\t}\n\t\tif pkgErr != nil && pkg.Error == nil {\n\t\t\tpkg.Error = &PackageError{Err: pkgErr}\n\t\t\tpkg.Incomplete = true\n\t\t}\n\t}\n\n\tmatchers := make([]func(string) bool, len(patterns))\n\tfor i, p := range patterns {\n\t\tif strings.Contains(p, \"...\") {\n\t\t\tmatchers[i] = pkgpattern.MatchPattern(p)\n\t\t}\n\t}\n\treturn pkgs, nil\n}\n\n// EnsureImport ensures that package p imports the named package.\nfunc EnsureImport(s *modload.Loader, p *Package, pkg string) {","sourceCodeStart":3465,"sourceCodeEnd":3501,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/load/pkg.go#L3465-L3501","documentation":"A loaded package's `Module` differs in path or version from the `rootMod` resolved from the first argument. The package@version workflow requires ALL package arguments to be provided by the SAME module at the SAME version. This fires when arguments span multiple modules (common in multi-module repositories).","triggerScenarios":"`go install example.com/mod/pkg1 example.com/othermod/pkg2@v1.0.0` where pkg2 lives in a different module; a `...` wildcard in a multi-module repo crosses module boundaries.","commonSituations":"Multi-module repositories (several go.mod files in one VCS); passing packages from sibling modules; wildcards that escape the root module's tree.","solutions":["Ensure every argument belongs to the same module path prefix as the first argument.","Split the install into separate `go install moduleA/...@vA` and `go install moduleB/...@vB` invocations.","Use `go list -m` per package to confirm module boundaries before constructing the command."],"exampleFix":"// before\ngo install example.com/mod/a example.com/sibling/b@v1.0.0\n\n// after\ngo install example.com/mod/a@v1.0.0\ngo install example.com/sibling/b@v1.0.0","handlingStrategy":"validation","validationCode":"// Ensure all package args share the same module prefix.\nfunc sameModule(args []string, mod string) bool {\n    for _, a := range args {\n        p, _, _ := strings.Cut(a, \"@\")\n        if !strings.HasPrefix(p, mod+\"/\") && p != mod {\n            return false\n        }\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Group install arguments by module; never mix modules in one command.","In multi-module repos, install each module separately at its own version.","Verify module boundaries with `go list -m` before constructing commands."],"tags":["go-toolchain","module","multi-module","install"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}