{"record":{"id":"10e0de829c655c9d","repo":"golang/go","slug":"cannot-load-module-s-listed-in-go-work-file-w","errorCode":null,"errorMessage":"cannot load module %s listed in go.work file: %w","messagePattern":"cannot load module (.+?) listed in go\\.work file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":1043,"sourceCode":"\n\tvar modFiles []*modfile.File\n\tvar mainModules []module.Version\n\tvar indices []*modFileIndex\n\tvar errs []error\n\tfor _, modroot := range ld.modRoots {\n\t\tgomod := modFilePath(modroot)\n\t\tvar fixed bool\n\t\tdata, f, err := ReadModFile(gomod, fixVersion(ld, ctx, &fixed))\n\t\tif err != nil {\n\t\t\tif ld.inWorkspaceMode() {\n\t\t\t\tif tooNew, ok := err.(*gover.TooNewError); ok && !strings.HasPrefix(cfg.CmdName, \"work \") {\n\t\t\t\t\t// Switching to a newer toolchain won't help - the go.work has the wrong version.\n\t\t\t\t\t// Report this more specific error, unless we are a command like 'go work use'\n\t\t\t\t\t// or 'go work sync', which will fix the problem after the caller sees the TooNewError\n\t\t\t\t\t// and switches to a newer toolchain.\n\t\t\t\t\terr = errWorkTooOld(gomod, workFile, tooNew.GoVersion)\n\t\t\t\t} else {\n\t\t\t\t\terr = fmt.Errorf(\"cannot load module %s listed in go.work file: %w\",\n\t\t\t\t\t\tbase.ShortPath(filepath.Dir(gomod)), base.ShortPathError(err))\n\t\t\t\t}\n\t\t\t}\n\t\t\terrs = append(errs, err)\n\t\t\tcontinue\n\t\t}\n\t\tif ld.inWorkspaceMode() && !strings.HasPrefix(cfg.CmdName, \"work \") {\n\t\t\t// Refuse to use workspace if its go version is too old.\n\t\t\t// Disable this check if we are a workspace command like work use or work sync,\n\t\t\t// which will fix the problem.\n\t\t\tmv := gover.FromGoMod(f)\n\t\t\twv := gover.FromGoWork(workFile)\n\t\t\tif gover.Compare(mv, wv) > 0 && gover.Compare(mv, gover.GoStrictVersion) >= 0 {\n\t\t\t\terrs = append(errs, errWorkTooOld(gomod, workFile, mv))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L1025-L1061","documentation":"In workspace mode, loading one of the go.mod files referenced by go.work 'use' directives failed. The original error (potentially a TooNewError that was NOT rewritten because the command is not a 'work ' subcommand, or some other read/parse failure) is wrapped with the short path of the module directory. Errs are collected so multiple broken members can be reported together.","triggerScenarios":"A go.work 'use ./X' points at a directory whose go.mod is missing, unreadable, unparseable, or declares a go version too new for the toolchain AND the current command is not 'go work ...'. ReadModFile returns err, the workspace branch wraps it.","commonSituations":"A workspace member submodule was deleted/moved but not dropped from go.work; a member go.mod has merge-conflict artifacts; toolchain too old for a member's go directive; relative 'use' path broken after a directory rename.","solutions":["Open the reported module directory and fix/restore its go.mod.","If the member no longer exists, drop it: 'go work edit -dropuse=./X'.","For a TooNewError root cause, upgrade the toolchain (GOTOOLCHAIN=auto) or lower the member's go directive.","Re-run; additional member errors may surface one batch at a time."],"exampleFix":"// before\n$ go build ./...\n// cannot load module ./svc-b listed in go.work: reading svc-b/go.mod: open: no such file\n\n// after\n$ go work edit -dropuse=./svc-b     // svc-b was removed\n$ go build ./...","handlingStrategy":"validation","validationCode":"// Verify every go.work 'use' member has a loadable go.mod.\ndata, _ := os.ReadFile(\"go.work\")\nwf, _ := modfile.ParseWork(\"go.work\", data, nil)\nfor _, u := range wf.Use {\n    gomod := filepath.Join(u.Path, \"go.mod\")\n    if _, err := os.Stat(gomod); err != nil {\n        return fmt.Errorf(\"workspace member %s missing go.mod: %w\", u.Path, err)\n    }\n    if _, err := modfile.Parse(gomod, mustReadFile(gomod), nil); err != nil {\n        return fmt.Errorf(\"workspace member %s go.mod invalid: %w\", u.Path, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"cannot load module\") && bytes.Contains(out, \"listed in go.work\")) {\n    // drop the stale member, then retry\n    member := extractMemberFromError(out) // your helper\n    _ = exec.Command(\"go\", \"work\", \"edit\", \"-dropuse=\"+member).Run()\n    out, err = exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\n}\nreturn err","preventionTips":["Keep go.work 'use' entries in sync with actual submodules.","When deleting a submodule, immediately 'go work edit -dropuse=...'.","Pre-build: stat each member's go.mod.","Upgrade toolchain proactively so member TooNewErrors do not surface."],"tags":["go-work","use-directive","go-mod","missing-module","workspace"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}