gohugoio/hugo · error

{path} already exists

Error message

{path} already exists

What it means

Even with --force, CreateProject pre-checks each file the skeleton would write and refuses to overwrite any that already exists. The offending path is named in the error message. This protects configured files (e.g. hugo.toml, archetype files) from being silently destroyed.

Source

Thrown at create/skeletons/skeletons.go:118

		}

		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{
		"baseURL": "https://example.org/",
		"locale":  "en-us",
		"title":   "My New Hugo Project",
	}

	err := createProjectConfig(sourceFs, createpath, projectConfig, format)
	if err != nil {
		return err
	}

	defaultArchetype := map[string]any{
		"title": "{{ replace .File.ContentBaseName \"-\" \" \" | title }}",

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Rename or remove the specific file named in the error message.
  2. Manually merge the scaffolded content instead of overwriting.
  3. Scaffold into a fresh directory and copy files in selectively.

Example fix

// before
hugo new site . --force   # hugo.toml exists
// after
mv hugo.toml hugo.toml.bak
hugo new site . --force
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check skeleton files before forcing a scaffold
for _, p := range skeletonFiles {
    if _, err := os.Stat(filepath.Join(createpath, p)); err == nil {
        return fmt.Errorf("%s already exists; rename or remove it", p)
    }
}

Prevention

When it happens

Trigger: `hugo new site . --force` where one of the skeleton files (such as hugo.<format> or a file under the scaffold) already exists in the target.

Common situations: Re-scaffolding over a project that already has a hugo.toml or default archetype; partial previous scaffold left files behind.

Related errors


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