{"record":{"id":"b6e93879a1f0be91","repo":"gohugoio/hugo","slug":"failed-to-vendor-module-w","errorCode":null,"errorMessage":"failed to vendor module: %w","messagePattern":"failed to vendor module: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":241,"sourceCode":"\t\t\tcontinue\n\t\t}\n\n\t\t// See https://github.com/gohugoio/hugo/issues/8239\n\t\t// This is an error situation. We need something to vendor.\n\t\tif t.Mounts() == nil {\n\t\t\treturn fmt.Errorf(\"cannot vendor module %q, need at least one mount\", t.PathVersionQuery(false))\n\t\t}\n\n\t\tfmt.Fprintln(&modulesContent, \"# \"+t.PathVersionQuery(true)+\" \"+t.Version())\n\n\t\tdir := t.Dir()\n\n\t\tfor _, mount := range t.Mounts() {\n\t\t\tsourceFilename := filepath.Join(dir, mount.Source)\n\t\t\ttargetFilename := filepath.Join(vendorDir, t.PathVersionQuery(true), mount.Source)\n\t\t\tfi, err := c.fs.Stat(sourceFilename)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to vendor module: %w\", err)\n\t\t\t}\n\n\t\t\tif fi.IsDir() {\n\t\t\t\tif err := hugio.CopyDir(c.fs, sourceFilename, targetFilename, nil); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to copy module to vendor dir: %w\", err)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttargetDir := filepath.Dir(targetFilename)\n\n\t\t\t\tif err := c.fs.MkdirAll(targetDir, 0o755); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to make target dir: %w\", err)\n\t\t\t\t}\n\n\t\t\t\tif err := hugio.CopyFile(c.fs, sourceFilename, targetFilename); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to copy module file to vendor: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t}","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/client.go#L223-L259","documentation":"Returned by Client.Vendor when c.fs.Stat(sourceFilename) fails for a mount's source path inside the module directory. sourceFilename is filepath.Join(dir, mount.Source). The error is wrapped with %w so the underlying fs error (usually 'file does not exist') is unwrappable. This guards against declared mounts pointing at files/dirs that are not actually present in the dependency.","triggerScenarios":"Running `hugo mod vendor` when a module's [[module.mounts]] source path does not exist on disk relative to the module's Dir(). Common when the mount source was renamed/removed in a newer module version but the consuming project pins an older config, or when a mount points to a path only present on a specific platform.","commonSituations":"Module author removed a directory (e.g. 'i18n') but a mount still references it; typo in mount.Source; a module pinned to a version that predates a directory the consuming project expects; vendoring after a partial git checkout of a module.","solutions":["Check the wrapped error for the exact missing path, then verify that path exists in the module version you are pulling.","Correct mount.Source in the module config to match the real directory/file name.","Bump or pin the module to a version that contains the expected files.","Remove mounts for paths you do not actually need."],"exampleFix":"# before\n[[module.mounts]]\nsource = \"i18n\"   # directory no longer exists upstream\ntarget = \"i18n\"\n\n# after\n[[module.mounts]]\nsource = \"locales\"\ntarget = \"i18n\"","handlingStrategy":"validation","validationCode":"// Verify each mount source exists before vending.\nfunc mountsExist(fs afero.Fs, dir string, mounts []Mount) error {\n    for _, mnt := range mounts {\n        if _, err := fs.Stat(filepath.Join(dir, mnt.Source)); err != nil {\n            return fmt.Errorf(\"mount source missing: %s: %w\", mnt.Source, err)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := client.Vendor(); err != nil {\n    if errors.Is(err, os.ErrNotExist) || strings.Contains(err.Error(), \"failed to vendor module\") {\n        // re-download module or fix mount.Source\n    }\n}","preventionTips":["Keep mount.Source paths in sync with the module's real directory layout.","Pin module versions whose file layout matches your mounts."],"tags":["modules","vendoring","mounts","filesystem","missing-file"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}