gohugoio/hugo · error

{createpath} already exists and is not empty. See --force.

Error message

{createpath} already exists and is not empty. See --force.

What it means

CreateProject will not scaffold into a non-empty existing directory unless --force is passed. This guard prevents clobbering an existing project's contents.

Source

Thrown at create/skeletons/skeletons.go:106

		return err
	}

	return copyFiles(createpath, sourceFs, themeFs)
}

// CreateProject creates a project skeleton.
func CreateProject(createpath string, sourceFs afero.Fs, force bool, format string) error {
	format = strings.ToLower(format)
	if exists, _ := helpers.Exists(createpath, sourceFs); exists {
		if isDir, _ := helpers.IsDir(createpath, sourceFs); !isDir {
			return errors.New(createpath + " already exists but not a directory")
		}

		isEmpty, _ := helpers.IsEmpty(createpath, sourceFs)

		switch {
		case !isEmpty && !force:
			return errors.New(createpath + " already exists and is not empty. See --force.")
		case !isEmpty && force:
			var all []string
			fs.WalkDir(projectFs, ".", func(path string, d fs.DirEntry, err error) error {
				if d.IsDir() && path != "." {
					all = append(all, path)
				}
				return nil
			})
			all = append(all, filepath.Join(createpath, "hugo."+format))
			for _, path := range all {
				if exists, _ := helpers.Exists(path, sourceFs); exists {
					return errors.New(path + " already exists")
				}
			}
		}
	}

	projectConfig := map[string]any{

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Pass --force to allow scaffolding into a non-empty directory.
  2. Target an empty directory instead.
  3. Remove the conflicting contents before scaffolding.

Example fix

// before
hugo new site .   # directory not empty
// after
hugo new site . --force
Defensive patterns

Strategy: validation

Validate before calling

// Reject non-empty target unless force is intended
if entries, err := os.ReadDir(createpath); err == nil && len(entries) > 0 && !force {
    return fmt.Errorf("%s not empty; pass --force to proceed", createpath)
}

Prevention

When it happens

Trigger: `hugo new site .` (or any existing non-empty directory) without --force.

Common situations: Re-scaffolding into an already-populated project; targeting a directory that holds a git repo or other files.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/0ae130fd92cc3222. Report an issue: GitHub.