golang/go · error
directory %s is not a package listed in vendor/modules.txt
Error message
directory %s is not a package listed in vendor/modules.txt
What it means
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.
Source
Thrown at src/cmd/go/internal/modload/load.go:617
}
// Note: The checks for @ here are just to avoid misinterpreting
// the module cache directories (formerly GOPATH/src/mod/foo@v1.5.2/bar).
// It's not strictly necessary but helpful to keep the checks.
var pkgNotFoundErr error
pkgNotFoundLongestPrefix := ""
for _, mainModule := range ld.MainModules.Versions() {
modRoot := ld.MainModules.ModRoot(mainModule)
if modRoot != "" && str.HasFilePathPrefix(absDir, modRoot) && !strings.Contains(absDir[len(modRoot):], "@") {
suffix := filepath.ToSlash(str.TrimFilePathPrefix(absDir, modRoot))
if pkg, found := strings.CutPrefix(suffix, "vendor/"); found {
if cfg.BuildMod != "vendor" {
return "", fmt.Errorf("without -mod=vendor, directory %s has no package path", absDir)
}
readVendorList(VendorDir(ld))
if _, ok := vendorPkgModule[pkg]; !ok {
return "", fmt.Errorf("directory %s is not a package listed in vendor/modules.txt", absDir)
}
return pkg, nil
}
mainModulePrefix := ld.MainModules.PathPrefix(mainModule)
if mainModulePrefix == "" {
pkg := suffix
if pkg == "builtin" {
// "builtin" is a pseudo-package with a real source file.
// It's not included in "std", so it shouldn't resolve from "."
// within module "std" either.
return "", errPkgIsBuiltin
}
return pkg, nil
}
pkg := pathpkg.Join(mainModulePrefix, suffix)
if _, ok, err := dirInModule(pkg, mainModulePrefix, modRoot, true); err != nil {View on GitHub (pinned to b6b368adc5)
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.
Example fix
# before — stale vendor manifest # (vendor/modules.txt missing a package that exists in vendor/) go build -mod=vendor ./vendor/example.com/newpkg # error # after — regenerate vendor tree go mod vendor go build -mod=vendor ./...
Defensive patterns
Strategy: validation
Prevention
- 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'.
When it happens
Trigger: 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'.
Common situations: 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/.
Related errors
- without -mod=vendor, directory %s has no package path
- use of vendored package not allowed
- can't resolve module using the vendor directory (Use -mod=m
- cannot find package in: %s
- import lookup disabled by -mod=%s
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/9e62f2db0edf3e57.
Report an issue: GitHub.