{"record":{"id":"be9d09f2c9d6a260","repo":"golang/go","slug":"can-t-resolve-module-using-the-vendor-directory","errorCode":null,"errorMessage":"can't resolve module using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)","messagePattern":"can't resolve module using the vendor directory\n\t\\(Use -mod=mod or -mod=readonly to bypass\\.\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cmd/go/internal/modload/list.go","lineNumber":269,"sourceCode":"\t\t\t\t\t// is no such root we should have loaded a non-nil mg.\n\t\t\t\t\tpanic(fmt.Sprintf(\"internal error: root requirement expected but not found for %v\", arg))\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tv = mg.Selected(arg)\n\t\t\t}\n\t\t\tif v == \"none\" && mgErr != nil {\n\t\t\t\t// mgErr is already set, so just skip this module.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif v != \"none\" {\n\t\t\t\tmods = append(mods, moduleInfo(ld, ctx, rs, module.Version{Path: arg, Version: v}, mode, reuse))\n\t\t\t} else if cfg.BuildMod == \"vendor\" {\n\t\t\t\t// In vendor mode, we can't determine whether a missing module is “a\n\t\t\t\t// known dependency” because the module graph is incomplete.\n\t\t\t\t// Give a more explicit error message.\n\t\t\t\tmods = append(mods, &modinfo.ModulePublic{\n\t\t\t\t\tPath:  arg,\n\t\t\t\t\tError: modinfoError(arg, \"\", errors.New(\"can't resolve module using the vendor directory\\n\\t(Use -mod=mod or -mod=readonly to bypass.)\")),\n\t\t\t\t})\n\t\t\t} else if mode&ListVersions != 0 {\n\t\t\t\t// Don't make the user provide an explicit '@latest' when they're\n\t\t\t\t// explicitly asking what the available versions are. Instead, return a\n\t\t\t\t// module with version \"none\", to which we can add the requested list.\n\t\t\t\tmods = append(mods, &modinfo.ModulePublic{Path: arg})\n\t\t\t} else {\n\t\t\t\tmods = append(mods, &modinfo.ModulePublic{\n\t\t\t\t\tPath:  arg,\n\t\t\t\t\tError: modinfoError(arg, \"\", errors.New(\"not a known dependency\")),\n\t\t\t\t})\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tvar matches []module.Version\n\t\tfor _, m := range mg.BuildList() {\n\t\t\tif match(m.Path) {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/list.go#L251-L287","documentation":"In `-mod=vendor` mode the module graph is intentionally incomplete: only vendored modules are visible. When a listed module path resolves to version \"none\" (absent), the go command cannot tell whether it is a real but un-vendored dependency, so it reports this per-module Error and points you at mod/readonly to query the full graph.","triggerScenarios":"`go list -m <path>` (or any module-listing command) with cfg.BuildMode==vendor where <path> is not present in the vendor/modules.txt or the build list.","commonSituations":"Querying a candidate dependency while vendored; checking whether something is a dependency before vendoring it; typos in the path.","solutions":["Re-run with -mod=mod or -mod=readonly to consult the complete module graph.","Add the dependency (`go get <path>` then `go mod vendor`) so it becomes resolvable.","Verify the module path spelling against go.mod / vendor/modules.txt."],"exampleFix":"# before\n$ go list -m example.com/newdep   # -mod=vendor in effect\n# module example.com/newdep ... Error: can't resolve module using the vendor directory\n\n# after\n$ go list -mod=readonly -m example.com/newdep","handlingStrategy":"validation","validationCode":"// Before resolving a possibly-un-vendored module, check vendor/modules.txt.\nfunc isVendored(modPath string) bool {\n    b, err := os.ReadFile(\"vendor/modules.txt\")\n    if err != nil { return false }\n    return bytes.Contains(b, []byte(\"# \"+modPath+\" \"))\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["For dependency queries under vendor mode, switch to -mod=readonly.","Run `go mod vendor` after adding any dependency used in vendored builds.","Don't rely on `go list -m <path>` to discover new deps while vendored."],"tags":["vendor","module-resolution","go-list","build-mode"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}