gohugoio/hugo · error
target path "{targetDir}" exists but is not a directory
Error message
target path "{targetDir}" exists but is not a directory What it means
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.
Source
Thrown at commands/import.go:166
if entry.IsDir() {
subDir := filepath.Join(jekyllRoot, entry.Name())
if isPostDir, hasAnyPostInDir := c.retrieveJekyllPostDir(fs, subDir); isPostDir {
postDirs[entry.Name()] = hasAnyPostInDir
if hasAnyPostInDir {
hasAnyPost = true
}
}
}
}
}
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")
View on GitHub (pinned to 52c9bd7908)
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
Example fix
# before hugo import jekyll ~/blog ~/blog.out # blog.out is a file # after rm ~/blog.out && hugo import jekyll ~/blog ~/blog.out
Defensive patterns
Strategy: validation
Validate before calling
if exists, _ := helpers.Exists(targetDir, fs); exists {
if isDir, _ := helpers.IsDir(targetDir, fs); !isDir {
return errors.New("target is a file, not a directory")
}
} Prevention
- Pre-check the target path with os.Stat before import
- Use a fresh or empty directory as the import target
When it happens
Trigger: `hugo import jekyll <src> <target>` where <target> resolves to an existing file path.
Common situations: 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.
Related errors
- target path "{targetDir}" exists and is not empty
- {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/0a83988a4eb22d82.
Report an issue: GitHub.