gohugoio/hugo · warning

target path "%s" exists and is not empty

Error message

target path "%s" exists and is not empty

What it means

Returned by `hugo import jekyll` when the target directory already exists, contains files, and --force was not given (commands/import.go:169-173). This is a safety guard: the importer writes a whole project scaffold and converted content into the target, and refuses to mingle with or overwrite existing files unless explicitly forced.

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 8a468df065)

Solutions

  1. If overwriting the existing contents is intended (e.g. a re-run), add --force: `hugo import jekyll <src> <target> --force`.
  2. Otherwise choose a new empty/non-existent target directory and merge results manually afterwards.
  3. If the only content is .git, either use --force (import won't touch .git) or import to a temp dir and move files into the repo.

Example fix

# before
hugo import jekyll ./old-blog ./new-site   # ./new-site has .git
# after
hugo import jekyll ./old-blog ./new-site --force
Defensive patterns

Strategy: validation

Validate before calling

entries, err := os.ReadDir(target)
if err == nil && len(entries) > 0 {
    return fmt.Errorf("%q is not empty; use a fresh directory or pass --force", target)
}

Type guard

func isEmptyDir(path string) bool {
    entries, err := os.ReadDir(path)
    return err == nil && len(entries) == 0
}

Prevention

When it happens

Trigger: Running `hugo import jekyll <jekyllRoot> <target>` where <target> is an existing non-empty directory without passing `--force`. Common exact cases: re-running the import after a partial/failed first attempt, or targeting a directory that already holds a `.git` folder or README.

Common situations: Re-running the import to pick up fixes after the first run errored partway; targeting a freshly `git init`-ed repo (the .git directory makes it non-empty); pointing at the Jekyll source directory itself by mistake.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/06ab7b0509b484e2.json. Report an issue: GitHub ↗.