{"record":{"id":"9e62f2db0edf3e57","repo":"golang/go","slug":"directory-s-is-not-a-package-listed-in-vendor-mod","errorCode":null,"errorMessage":"directory %s is not a package listed in vendor/modules.txt","messagePattern":"directory (.+?) is not a package listed in vendor/modules\\.txt","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/load.go","lineNumber":617,"sourceCode":"\t}\n\n\t// Note: The checks for @ here are just to avoid misinterpreting\n\t// the module cache directories (formerly GOPATH/src/mod/foo@v1.5.2/bar).\n\t// It's not strictly necessary but helpful to keep the checks.\n\tvar pkgNotFoundErr error\n\tpkgNotFoundLongestPrefix := \"\"\n\tfor _, mainModule := range ld.MainModules.Versions() {\n\t\tmodRoot := ld.MainModules.ModRoot(mainModule)\n\t\tif modRoot != \"\" && str.HasFilePathPrefix(absDir, modRoot) && !strings.Contains(absDir[len(modRoot):], \"@\") {\n\t\t\tsuffix := filepath.ToSlash(str.TrimFilePathPrefix(absDir, modRoot))\n\t\t\tif pkg, found := strings.CutPrefix(suffix, \"vendor/\"); found {\n\t\t\t\tif cfg.BuildMod != \"vendor\" {\n\t\t\t\t\treturn \"\", fmt.Errorf(\"without -mod=vendor, directory %s has no package path\", absDir)\n\t\t\t\t}\n\n\t\t\t\treadVendorList(VendorDir(ld))\n\t\t\t\tif _, ok := vendorPkgModule[pkg]; !ok {\n\t\t\t\t\treturn \"\", fmt.Errorf(\"directory %s is not a package listed in vendor/modules.txt\", absDir)\n\t\t\t\t}\n\t\t\t\treturn pkg, nil\n\t\t\t}\n\n\t\t\tmainModulePrefix := ld.MainModules.PathPrefix(mainModule)\n\t\t\tif mainModulePrefix == \"\" {\n\t\t\t\tpkg := suffix\n\t\t\t\tif pkg == \"builtin\" {\n\t\t\t\t\t// \"builtin\" is a pseudo-package with a real source file.\n\t\t\t\t\t// It's not included in \"std\", so it shouldn't resolve from \".\"\n\t\t\t\t\t// within module \"std\" either.\n\t\t\t\t\treturn \"\", errPkgIsBuiltin\n\t\t\t\t}\n\t\t\t\treturn pkg, nil\n\t\t\t}\n\n\t\t\tpkg := pathpkg.Join(mainModulePrefix, suffix)\n\t\t\tif _, ok, err := dirInModule(pkg, mainModulePrefix, modRoot, true); err != nil {","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/load.go#L599-L635","documentation":"Thrown by resolveLocalPackage (load.go:617) when the directory is inside vendor/ AND -mod=vendor is active, but the package (the suffix after 'vendor/') is not listed in vendor/modules.txt. After confirming vendor mode, the code calls readVendorList and checks vendorPkgModule[pkg]. If the package is not registered in the vendor manifest, the directory is not a recognized vendored package.","triggerScenarios":"The vendor/ directory contains a package subdirectory that was added manually or is stale, but vendor/modules.txt does not list it. This happens when -mod=vendor is set and the user points at a vendor subpath not tracked by 'go mod vendor'.","commonSituations":"Manually copying a package into vendor/ without updating modules.txt. A stale vendor/ directory after go.mod requirements changed but 'go mod vendor' was not re-run. Third-party files dropped into vendor/.","solutions":["Regenerate the vendor directory and its manifest: run 'go mod vendor'.","Remove any manually-added directories under vendor/ that are not real vendored dependencies.","Ensure the package you are referencing is an actual dependency in go.mod before vendoring."],"exampleFix":"# before — stale vendor manifest\n# (vendor/modules.txt missing a package that exists in vendor/)\n\ngo build -mod=vendor ./vendor/example.com/newpkg\n# error\n\n# after — regenerate vendor tree\ngo mod vendor\ngo build -mod=vendor ./...","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'go mod vendor' whenever go.mod requirements change to keep vendor/modules.txt in sync.","Never manually add directories under vendor/ — always go through the module system.","If you see unexpected vendor entries, delete vendor/ and regenerate with 'go mod vendor'."],"tags":["vendor","modules-txt","package-resolution","go-mod-vendor"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}