{"record":{"id":"0a83988a4eb22d82","repo":"gohugoio/hugo","slug":"target-path-targetdir-exists-but-is-not-a-dire","errorCode":null,"errorMessage":"target path \"{targetDir}\" exists but is not a directory","messagePattern":"target path \"(.+?)\" exists but is not a directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/import.go","lineNumber":166,"sourceCode":"\t\t\tif entry.IsDir() {\n\t\t\t\tsubDir := filepath.Join(jekyllRoot, entry.Name())\n\t\t\t\tif isPostDir, hasAnyPostInDir := c.retrieveJekyllPostDir(fs, subDir); isPostDir {\n\t\t\t\t\tpostDirs[entry.Name()] = hasAnyPostInDir\n\t\t\t\t\tif hasAnyPostInDir {\n\t\t\t\t\t\thasAnyPost = true\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn postDirs, hasAnyPost\n}\n\nfunc (c *importCommand) createProjectFromJekyll(jekyllRoot, targetDir string, jekyllPostDirs map[string]bool) error {\n\tfs := &afero.OsFs{}\n\tif exists, _ := helpers.Exists(targetDir, fs); exists {\n\t\tif isDir, _ := helpers.IsDir(targetDir, fs); !isDir {\n\t\t\treturn errors.New(\"target path \\\"\" + targetDir + \"\\\" exists but is not a directory\")\n\t\t}\n\n\t\tisEmpty, _ := helpers.IsEmpty(targetDir, fs)\n\n\t\tif !isEmpty && !c.force {\n\t\t\treturn errors.New(\"target path \\\"\" + targetDir + \"\\\" exists and is not empty\")\n\t\t}\n\t}\n\n\tjekyllConfig := c.loadJekyllConfig(fs, jekyllRoot)\n\n\tmkdir(targetDir, \"layouts\")\n\tmkdir(targetDir, \"content\")\n\tmkdir(targetDir, \"archetypes\")\n\tmkdir(targetDir, \"static\")\n\tmkdir(targetDir, \"data\")\n\tmkdir(targetDir, \"themes\")\n","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/import.go#L148-L184","documentation":"In Jekyll import (createProjectFromJekyll), if the target path exists but is a regular file rather than a directory (helpers.IsDir false at import.go:165), the import refuses to proceed to avoid clobbering a file.","triggerScenarios":"`hugo import jekyll <src> <target>` where <target> resolves to an existing file path.","commonSituations":"Pointing the import target at an existing file; a stale file left at the intended project location; a symlink target that resolves to a file.","solutions":["Remove or rename the existing file at the target path","Choose a different target directory that does not exist or is already a directory","Verify the target path with os.Stat before running import"],"exampleFix":"# before\nhugo import jekyll ~/blog ~/blog.out   # blog.out is a file\n# after\nrm ~/blog.out && hugo import jekyll ~/blog ~/blog.out","handlingStrategy":"validation","validationCode":"if exists, _ := helpers.Exists(targetDir, fs); exists {\n    if isDir, _ := helpers.IsDir(targetDir, fs); !isDir {\n        return errors.New(\"target is a file, not a directory\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-check the target path with os.Stat before import","Use a fresh or empty directory as the import target"],"tags":["import","jekyll","filesystem","go","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}