{"record":{"id":"e39864ac83245b91","repo":"gohugoio/hugo","slug":"failed-to-make-target-dir-w","errorCode":null,"errorMessage":"failed to make target dir: %w","messagePattern":"failed to make target dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/client.go","lineNumber":252,"sourceCode":"\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 {\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.","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/modules/client.go#L234-L270","documentation":"Returned by Client.Vendor when c.fs.MkdirAll(targetDir, 0o755) fails for a file-type mount, before copying the file itself. targetDir is the parent of the vendored file path. Wrapped with %w. The file mount path is filepath.Join(vendorDir, pathVersion, mount.Source).","triggerScenarios":"Running `hugo mod vendor` where a mount source is a single file whose target parent directory cannot be created: permission denied, read-only filesystem, invalid path characters, or a path collision with an existing file.","commonSituations":"Working directory or _vendor is read-only; a previous failed vendor left a file where a directory is now expected; OS path restrictions (Windows reserved names); running Hugo as a user lacking write access to the project.","solutions":["Read the wrapped error for the OS cause (permission, read-only, invalid name).","Ensure the project working dir is writable: `chmod -R u+w .` or remove a stale _vendor dir.","Delete _vendor and re-run `hugo mod vendor` to get a clean target tree.","Avoid mount.Source paths that collide with file/directory names already vendored."],"exampleFix":"# before: stale _vendor from a failed run blocks mkdir\nrm -rf _vendor\nhugo mod vendor   # still fails due to perms\n\n# after\nchmod -R u+w . && rm -rf _vendor\nhugo mod vendor","handlingStrategy":"validation","validationCode":"// Ensure the _vendor tree is clean/writable before vendoring.\nfunc prepareVendorDir(fs afero.Fs, dir string) error {\n    if err := fs.RemoveAll(dir); err != nil {\n        return err\n    }\n    return fs.MkdirAll(dir, 0o755)\n}","typeGuard":null,"tryCatchPattern":"if err := client.Vendor(); err != nil {\n    if strings.Contains(err.Error(), \"failed to make target dir\") {\n        // remove stale _vendor, fix permissions, retry\n    }\n}","preventionTips":["Delete _vendor before re-vendoring to avoid stale file/dir conflicts.","Confirm the working directory is writable.","Avoid Windows-reserved names in mount.Source paths."],"tags":["modules","vendoring","filesystem","mkdir","permissions"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}