{"id":"86091413e8ad1876","repo":"gohugoio/hugo","slug":"target-path-s-exists-but-is-not-a-directory","errorCode":null,"errorMessage":"target path \"%s\" 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/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/import.go#L148-L184","documentation":"Returned by `hugo import jekyll` when the given target path already exists but is a regular file rather than a directory (commands/import.go:164-167). The importer needs to scaffold a Hugo project tree (layouts/, content/, static/, …) inside the target, which is impossible if the path is occupied by a file, so it aborts before touching anything.","triggerScenarios":"Running `hugo import jekyll <jekyllRoot> <target>` where <target> resolves to an existing regular file — e.g. `hugo import jekyll ./blog ./site` when `./site` is a file, or accidentally passing a filename (like a config file) as the second positional argument.","commonSituations":"Swapped or mistyped positional arguments (source and target reversed, or a file path pasted as target); a leftover file with the intended project name; scripts that previously `touch`ed the target path.","solutions":["Verify the second argument: `ls -l <target>` — if it's a file you didn't intend, choose a different target directory name.","If the file is disposable, remove it (`rm <target>`) and re-run the import.","Point the import at a fresh, non-existent path (Hugo will create the directory tree)."],"exampleFix":"# before\nhugo import jekyll ./old-blog ./site   # ./site is a file\n# after\nrm ./site && hugo import jekyll ./old-blog ./site","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(target); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%q exists and is a file; choose another target or remove it\", target)\n}","typeGuard":"func isDir(path string) bool {\n    info, err := os.Stat(path)\n    return err == nil && info.IsDir()\n}","tryCatchPattern":null,"preventionTips":["Stat the import target before running hugo import and confirm it is a directory or absent","Never reuse a path that a previous run may have created as a file","Prefer letting the tool create a fresh, non-existent target path"],"tags":["hugo","import","jekyll","filesystem","cli"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}