{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/client.go#L234-L270","documentation":"In `hugo mod vendor` (modules/client.go:252), when a mount source is a single file rather than a directory, Hugo first creates the target's parent directory inside _vendor/ with MkdirAll(0o755). This error means that directory creation failed, so the file copy never starts.","triggerScenarios":"c.fs.MkdirAll(filepath.Dir(targetFilename), 0o755) fails for a file-typed mount during vendoring — e.g. no write permission in the project, a path component in _vendor/ already exists as a regular file, or the filesystem is read-only/full.","commonSituations":"Running hugo mod vendor in a read-only checkout or container; a previous partial vendor left a file where a directory is now needed; overly long paths on Windows; restrictive umask/ACLs in CI.","solutions":["Delete the existing _vendor directory and re-run hugo mod vendor to clear conflicting leftovers.","Ensure the working directory is writable by the user running Hugo (fix ownership/ACLs, don't run in a read-only mount).","Check free disk space and, on Windows, path-length limits.","Inspect the wrapped error for the exact path that failed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify the target parent directory can be created\nif err := os.MkdirAll(filepath.Dir(targetPath), 0o755); err != nil {\n    return fmt.Errorf(\"cannot create vendor target: %w\", err)\n}","typeGuard":"func isPermissionErr(err error) bool { return errors.Is(err, fs.ErrPermission) }","tryCatchPattern":"if err := client.Vendor(); err != nil {\n    if errors.Is(err, fs.ErrPermission) {\n        return fmt.Errorf(\"no write access to _vendor tree — fix ownership/permissions: %w\", err)\n    }\n    return err\n}","preventionTips":["Don't run vendoring as a different user than the one owning the project directory","Watch for path-length limits on Windows when modules have deeply nested mounts","Keep _vendor out of read-only bind mounts in containerized builds"],"tags":["hugo","modules","vendoring","filesystem","permissions"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}