gohugoio/hugo · error
target path "{targetDir}" exists and is not empty
Error message
target path "{targetDir}" exists and is not empty What it means
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).
Source
Thrown at commands/import.go:172
}
}
}
}
}
return postDirs, hasAnyPost
}
func (c *importCommand) createProjectFromJekyll(jekyllRoot, targetDir string, jekyllPostDirs map[string]bool) error {
fs := &afero.OsFs{}
if exists, _ := helpers.Exists(targetDir, fs); exists {
if isDir, _ := helpers.IsDir(targetDir, fs); !isDir {
return errors.New("target path \"" + targetDir + "\" exists but is not a directory")
}
isEmpty, _ := helpers.IsEmpty(targetDir, fs)
if !isEmpty && !c.force {
return errors.New("target path \"" + targetDir + "\" exists and is not empty")
}
}
jekyllConfig := c.loadJekyllConfig(fs, jekyllRoot)
mkdir(targetDir, "layouts")
mkdir(targetDir, "content")
mkdir(targetDir, "archetypes")
mkdir(targetDir, "static")
mkdir(targetDir, "data")
mkdir(targetDir, "themes")
c.createConfigFromJekyll(fs, targetDir, "yaml", jekyllConfig)
c.copyJekyllFilesAndFolders(jekyllRoot, filepath.Join(targetDir, "static"), jekyllPostDirs)
return nil
}View on GitHub (pinned to 52c9bd7908)
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
Example fix
# before hugo import jekyll ~/blog ~/existing-project # after hugo import jekyll ~/blog ~/existing-project --force
Defensive patterns
Strategy: validation
Validate before calling
if isEmpty, _ := helpers.IsEmpty(targetDir, fs); !isEmpty && !force {
return errors.New("target not empty; pass --force to overwrite")
} Prevention
- Use --force only when intentionally merging into an existing project
- Default to a fresh, empty target directory for imports
When it happens
Trigger: `hugo import jekyll <src> <target>` (without --force) where <target> is a non-empty directory.
Common situations: Importing into an existing Hugo project directory; re-running import into the same target; pointing at a directory with unrelated files.
Related errors
- target path "{targetDir}" exists but is not a directory
- {jekyllRoot} is not a directory
- abort: jekyll root contains neither posts nor drafts
- filename not match
- must not be run from the file system root
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/27a7f9053017cc29.
Report an issue: GitHub.