{"record":{"id":"6530871c4f873c7c","repo":"golang/go","slug":"module-s-listed-in-go-work-file-requires-go-s","errorCode":null,"errorMessage":"module %s listed in go.work file requires go >= %s, but go.work %s go %s; to download and use go %s:\n\tgo work use","messagePattern":"module (.+?) listed in go\\.work file requires go >= (.+?), but go\\.work (.+?) go (.+?); to download and use go (.+?):\n\tgo work use","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":1167,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\trawGoVersion.Store(mainModule, gover.DefaultGoModVersion)\n\t\t}\n\t}\n\n\tld.requirements = rs\n\treturn ld.requirements, nil\n}\n\nfunc errWorkTooOld(gomod string, wf *modfile.WorkFile, goVers string) error {\n\tverb := \"lists\"\n\tif wf == nil || wf.Go == nil {\n\t\t// A go.work file implicitly requires go1.18\n\t\t// even when it doesn't list any version.\n\t\tverb = \"implicitly requires\"\n\t}\n\treturn fmt.Errorf(\"module %s listed in go.work file requires go >= %s, but go.work %s go %s; to download and use go %s:\\n\\tgo work use\",\n\t\tbase.ShortPath(filepath.Dir(gomod)), goVers, verb, gover.FromGoWork(wf), goVers)\n}\n\n// CheckReservedModulePath checks whether the module path is a reserved module path\n// that can't be used for a user's module.\nfunc CheckReservedModulePath(path string) error {\n\tif gover.IsToolchain(path) {\n\t\treturn errors.New(\"module path is reserved\")\n\t}\n\n\treturn nil\n}\n\n// CreateModFile initializes a new module by creating a go.mod file.\n//\n// If modPath is empty, CreateModFile will attempt to infer the path from the\n// directory location within GOPATH.\n//","sourceCodeStart":1149,"sourceCodeEnd":1185,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L1149-L1185","documentation":"errWorkTooOld: a module listed in go.work requires a newer Go version than go.work itself declares. Produced when a member's go.mod go directive exceeds the go.work go version (and the member is >= GoStrictVersion). The message tells the user to run 'go work use' which will bump go.work's go directive after they obtain the newer toolchain.","triggerScenarios":"go.work says 'go 1.21' but a member go.mod says 'go 1.22'; both are >= GoStrictVersion so the comparison gover.Compare(mv, wv) > 0 triggers errWorkTooOld. Also fires via the TooNewError branch in 1069's neighborhood.","commonSituations":"Adding/upgrading a dependency submodule that bumped its go directive; merging a newer member into an older workspace; CI toolchain behind the member requirements.","solutions":["Upgrade the toolchain to the required version (GOTOOLCHAIN=auto or go get toolchain@go1.X).","Run 'go work use' as the message instructs; it bumps the go.work go directive to match.","Manually edit go.work 'go X.Y' to >= the member's version.","If the member's high directive is unintended, lower that member's go directive instead."],"exampleFix":"// before\ngo.work:  go 1.21\nsvc-b/go.mod:  go 1.22\n// module svc-b listed in go.work requires go >= 1.22, but go.work lists go 1.21\n\n// after\n$ GOTOOLCHAIN=auto go work use   // go.work bumped to 'go 1.22'","handlingStrategy":"validation","validationCode":"// Ensure go.work go version >= every member's go directive.\ndata, _ := os.ReadFile(\"go.work\")\nwf, _ := modfile.ParseWork(\"go.work\", data, nil)\nwv := gover.FromGoWork(wf)\nfor _, u := range wf.Use {\n    mdata, _ := os.ReadFile(filepath.Join(u.Path, \"go.mod\"))\n    mf, _ := modfile.Parse(\"go.mod\", mdata, nil)\n    mv := gover.FromGoMod(mf)\n    if gover.Compare(mv, wv) > 0 {\n        return fmt.Errorf(\"bump go.work go to %s (member %s needs it)\", mv, u.Path)\n    }\n}","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"requires go >=\")) && bytes.Contains(out, \"go.work\") {\n    // bump toolchain then 'go work use' to realign\n    _ = os.Setenv(\"GOTOOLCHAIN\", \"auto\")\n    _ = exec.Command(\"go\", \"work\", \"use\").Run()\n    out, err = exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\n}\nreturn err","preventionTips":["Set GOTOOLCHAIN=auto so Go can self-upgrade to the workspace floor.","After bumping any member's go directive, run 'go work use' to bump go.work.","Track the max member go directive in CI and fail if go.work is behind.","Prefer bumping go.work over lowering members."],"tags":["go-work","version-mismatch","go-toolchain","workspace","too-new"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}