gohugoio/hugo · error

no existing content directory configured for this project

Error message

no existing content directory configured for this project

What it means

NewContent (the `hugo new` content path) stats the content filesystem root; if that stat fails, no content directory is mounted for the project and the command aborts. This happens when the content/ directory is absent or when module mounts remap content to a path that does not exist.

Solutions

  1. Create the content directory: `mkdir -p content`.
  2. Fix the module `mounts` so a content directory is actually mounted and exists.
  3. If starting fresh, scaffold the site with `hugo new site` first.

Example fix

// before
hugo new posts/hello.md   # no content dir
// after
mkdir -p content
hugo new posts/hello.md
Defensive patterns

Strategy: validation

Validate before calling

// Verify the content directory exists before hugo new
if _, err := os.Stat(filepath.Join(workDir, "content")); os.IsNotExist(err) {
    if mkErr := os.MkdirAll(filepath.Join(workDir, "content"), 0o755); mkErr != nil {
        return mkErr
    }
}

Prevention

When it happens

Trigger: `hugo new posts/x.md` when there is no content/ directory, or when a custom module mount points the content source at a missing path.

Common situations: A project where content/ was deleted; a mounts config that overrode the default content dir with a nonexistent target; running hugo new in a non-site directory.

Related errors


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

Appendix: source

Thrown at create/content.go:54

)

const (
	// DefaultArchetypeTemplateTemplate is the template used in 'hugo new project'
	// and the template we use as a fall back.
	DefaultArchetypeTemplateTemplate = `---
title: "{{ replace .File.ContentBaseName "-" " " | title }}"
date: {{ .Date }}
draft: true
---

`
)

// NewContent creates a new content file in h (or a full bundle if the archetype is a directory)
// in targetPath.
func NewContent(h *hugolib.HugoSites, kind, targetPath string, force bool) error {
	if _, err := h.BaseFs.Content.Fs.Stat(""); err != nil {
		return errors.New("no existing content directory configured for this project")
	}

	cf := hugolib.NewContentFactory(h)

	if kind == "" {
		var err error
		kind, err = cf.SectionFromFilename(targetPath)
		if err != nil {
			return err
		}
	}

	b := &contentBuilder{
		archeTypeFs: h.PathSpec.BaseFs.Archetypes.Fs,
		sourceFs:    h.PathSpec.Fs.Source,
		ps:          h.PathSpec,
		h:           h,
		cf:          cf,

View on GitHub (pinned to 52c9bd7908)