{"record":{"id":"27a7f9053017cc29","repo":"gohugoio/hugo","slug":"target-path-targetdir-exists-and-is-not-empty","errorCode":null,"errorMessage":"target path \"{targetDir}\" exists and is not empty","messagePattern":"target path \"(.+?)\" exists and is not empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/import.go","lineNumber":172,"sourceCode":"\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\n\tc.createConfigFromJekyll(fs, targetDir, \"yaml\", jekyllConfig)\n\n\tc.copyJekyllFilesAndFolders(jekyllRoot, filepath.Join(targetDir, \"static\"), jekyllPostDirs)\n\n\treturn nil\n}","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/import.go#L154-L190","documentation":"createProjectFromJekyll checks the target directory; if it exists, is a directory, but is not empty and the --force flag is not set, the import aborts to avoid overwriting existing project files (import.go:169-173).","triggerScenarios":"`hugo import jekyll <src> <target>` (without --force) where <target> is a non-empty directory.","commonSituations":"Importing into an existing Hugo project directory; re-running import into the same target; pointing at a directory with unrelated files.","solutions":["Pass the --force flag to allow import into a non-empty directory","Pick an empty or non-existent target directory","Clear the target directory first"],"exampleFix":"# before\nhugo import jekyll ~/blog ~/existing-project\n# after\nhugo import jekyll ~/blog ~/existing-project --force","handlingStrategy":"validation","validationCode":"if isEmpty, _ := helpers.IsEmpty(targetDir, fs); !isEmpty && !force {\n    return errors.New(\"target not empty; pass --force to overwrite\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use --force only when intentionally merging into an existing project","Default to a fresh, empty target directory for imports"],"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"}