{"id":"d4c2dc95e1b61057","repo":"gohugoio/hugo","slug":"failed-to-copy-module-file-to-vendor-w","errorCode":null,"errorMessage":"failed to copy module file to vendor: %w","messagePattern":"failed to copy module file to vendor: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":256,"sourceCode":"\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 {\n\t\t\tif err := hugio.CopyDir(c.fs, resourcesDir, filepath.Join(vendorDir, t.PathVersionQuery(true), files.FolderResources), nil); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to copy resources to vendor dir: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\t// Include the config directory if present.\n\t\tconfigDir := filepath.Join(dir, \"config\")\n\t\t_, err = c.fs.Stat(configDir)\n\t\tif err == nil {\n\t\t\tif err := hugio.CopyDir(c.fs, configDir, filepath.Join(vendorDir, t.PathVersionQuery(true), \"config\"), nil); err != nil {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/client.go#L238-L274","documentation":"In `hugo mod vendor` (modules/client.go:256), after successfully creating the target directory, Hugo copies a file-typed mount source into _vendor/ with hugio.CopyFile. This error wraps any failure of that single-file copy.","triggerScenarios":"hugio.CopyFile(c.fs, sourceFilename, targetFilename) fails for a mount whose source is a file — the source became unreadable between the earlier Stat and the copy, the target can't be created/written, or an I/O error occurs mid-copy.","commonSituations":"Permission problems on the source in the module cache or on the target under _vendor/; disk full during vendoring; file locked by another process (editor, indexer, AV) on Windows; a directory unexpectedly sitting at the target file path from an earlier partial vendor.","solutions":["Remove _vendor entirely and re-run hugo mod vendor to eliminate stale conflicting entries.","Verify the source file is readable (check the wrapped error's path against the module cache).","Ensure write permission and disk space in the project directory.","Close programs that may hold locks on the files (Windows)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check per-file readability for mounted files before vendoring\nif f, err := os.Open(sourceFile); err != nil {\n    return fmt.Errorf(\"mounted file unreadable: %w\", err)\n} else { f.Close() }","typeGuard":null,"tryCatchPattern":"if err := client.Vendor(); err != nil {\n    if strings.Contains(err.Error(), \"failed to copy module file to vendor\") {\n        return fmt.Errorf(\"a single-file mount could not be copied — check the file exists in the module: %w\", err)\n    }\n    return err\n}","preventionTips":["When mounting single files (e.g. a specific data file), verify the exact path exists in the module version you pinned","Pin module versions in config so a file present in one version doesn't vanish after an upgrade","Re-run `hugo mod verify` if the module cache may be corrupted"],"tags":["hugo","modules","vendoring","filesystem"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}