{"id":"7e4a38fd9442d83e","repo":"gohugoio/hugo","slug":"failed-to-copy-module-to-vendor-dir-w","errorCode":null,"errorMessage":"failed to copy module to vendor dir: %w","messagePattern":"failed to copy module to vendor dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":246,"sourceCode":"\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}\n\n\t\t// Include the resource cache if present.\n\t\tresourcesDir := filepath.Join(dir, files.FolderResources)\n\t\t_, err := c.fs.Stat(resourcesDir)\n\t\tif err == nil {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/client.go#L228-L264","documentation":"In `hugo mod vendor` (modules/client.go:246), when a mount source is a directory, Hugo recursively copies it into _vendor/<module-path>/ via hugio.CopyDir. Any I/O failure during that recursive copy surfaces as this wrapped error and aborts vendoring.","triggerScenarios":"hugio.CopyDir(c.fs, sourceFilename, targetFilename, nil) fails while copying a mounted directory tree — permission errors, unreadable files, disk full, or files disappearing mid-copy.","commonSituations":"Read-only or root-owned files inside the Go module cache (GOMODCACHE stores modules read-only, though reads normally suffice); no write permission or no space in the project's _vendor directory; antivirus/file-lock interference on Windows; symlinks or special files inside the mounted tree.","solutions":["Check the wrapped error for the failing path and whether it's a read (source) or write (target) failure.","Ensure the project directory is writable and has free disk space; delete a partially written _vendor and retry.","Fix permissions on the module cache (go clean -modcache then re-download if it's corrupted).","On Windows, exclude the project from real-time AV scanning while vendoring."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Confirm the module source dir exists and is readable\nif fi, err := os.Stat(mod.Dir()); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"module dir %q not accessible: %v\", mod.Dir(), err)\n}","typeGuard":null,"tryCatchPattern":"if err := client.Vendor(); err != nil {\n    if strings.Contains(err.Error(), \"failed to copy module to vendor dir\") {\n        // usually a filesystem issue: permissions, symlinks, or missing module cache\n        return fmt.Errorf(\"run 'hugo mod download' first, then re-vendor: %w\", err)\n    }\n    return err\n}","preventionTips":["Download modules (`hugo mod get` / `hugo mod download`) before vendoring so the module cache is populated","Avoid symlinks inside module content directories — copy semantics may not follow them","Check GOMODCACHE permissions; the cache is read-only by default which is fine for reads but confirm the destination side is writable"],"tags":["hugo","modules","vendoring","filesystem","permissions"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}