{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/client.go#L223-L259","documentation":"During `hugo mod vendor` (modules/client.go:241), Hugo stats each mount's source path (module dir + mount source) before copying it into _vendor/. If the stat fails — usually because the mounted path doesn't exist on disk — vendoring aborts with the wrapped filesystem error.","triggerScenarios":"c.fs.Stat(filepath.Join(t.Dir(), mount.Source)) returns an error while iterating a module's mounts in Client.Vendor(). Happens when a mount declares a source directory/file that is missing from the downloaded module.","commonSituations":"A module config mounting a directory that was renamed or deleted upstream; version bump of a dependency that removed a directory still referenced by mounts; stale module cache; case-sensitivity mismatches between macOS/Windows dev and Linux CI.","solutions":["Read the wrapped error to get the missing path, then check whether that directory exists in the module's source (see hugo mod graph for the cache dir, or the upstream repo).","Fix or remove the mount entry referencing the nonexistent path in the module's (or project's per-import) config.","Run hugo mod clean && hugo mod get -u to refresh a possibly corrupt module cache.","Pin the dependency to a version where the directory still exists."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check the vendor destination is writable before vendoring\nvendorDir := filepath.Join(workingDir, \"_vendor\")\nif err := os.MkdirAll(vendorDir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot create vendor dir: %w\", err)\n}","typeGuard":"func isVendorErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to vendor module\")\n}","tryCatchPattern":"if err := client.Vendor(); err != nil {\n    if errors.Is(err, fs.ErrPermission) {\n        return fmt.Errorf(\"vendor dir not writable: %w\", err)\n    }\n    return fmt.Errorf(\"vendoring failed, _vendor may be partial — delete it and retry: %w\", err)\n}","preventionTips":["Delete a partially written _vendor directory before retrying to avoid mixed state","Ensure disk space and write permission on the project directory before vendoring","Run vendoring from the project root, not a subdirectory"],"tags":["hugo","modules","vendoring","filesystem"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}