{"record":{"id":"4476bb3e9c98c968","repo":"golang/go","slug":"without-mod-vendor-directory-s-has-no-package-p","errorCode":null,"errorMessage":"without -mod=vendor, directory %s has no package path","messagePattern":"without -mod=vendor, directory (.+?) has no package path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/load.go","lineNumber":612,"sourceCode":"\t\t\tif absDir == cfg.GOROOTsrc {\n\t\t\t\treturn \"\", errPkgIsGorootSrc\n\t\t\t}\n\t\t\treturn ld.MainModules.PathPrefix(mod), nil\n\t\t}\n\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}","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/load.go#L594-L630","documentation":"Thrown by resolveLocalPackage (load.go:612) when the resolved absolute directory is under a main module's 'vendor/' subdirectory but the build mode (cfg.BuildMod) is not 'vendor'. The vendor directory only has importable package paths in vendor mode. Without -mod=vendor, the directory suffix like 'vendor/foo/bar' has no resolvable package path, so an error is returned before the vendor list is even read.","triggerScenarios":"Running 'go build ./vendor/...' or importing a path that resolves into a vendor/ directory when the module is not in vendor mode (cfg.BuildMod != \"vendor\"). This typically happens when -mod=mod or -mod=readonly is active and the user points directly at a vendored package.","commonSituations":"A project has a vendor/ directory (from 'go mod vendor') but the build is running without -mod=vendor, or GOFLAGS does not include -mod=vendor. Pointing tooling or IDE at a vendor subdirectory directly.","solutions":["Set the build to vendor mode: run 'go build -mod=vendor' or add 'GOFLAGS=-mod=vendor' to your environment.","Alternatively, reference the package by its import path rather than by its vendor filesystem path.","Remove the vendor/ directory if you intend to use network/module-cache mode instead."],"exampleFix":"# before\ngo build ./vendor/example.com/pkg\n\n# after\ngo build -mod=vendor ./...\n# or import by path, not by vendor filesystem location:\ngo build example.com/pkg","handlingStrategy":"validation","validationCode":"// Check build mode before pointing at vendor paths.\nfunc ensureVendorMode() error {\n    if cfg.BuildMod != \"vendor\" {\n        return fmt.Errorf(\"vendor directory requires -mod=vendor\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set -mod=vendor or GOFLAGS=-mod=vendor when building a project with a vendor/ directory.","Reference vendored packages by import path, not by their filesystem location under vendor/.","Run 'go mod vendor' to create a consistent vendor tree before enabling vendor mode."],"tags":["vendor","build-mode","package-resolution","go-build"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}