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
- Create the content directory: `mkdir -p content`.
- Fix the module `mounts` so a content directory is actually mounted and exists.
- 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
- Keep a content/ directory in every site project.
- If using custom mounts, ensure the mounted content source path exists.
- Scaffold sites with `hugo new site` so content/ is created.
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
- already exists
- already exists and is not empty. See --force.
- already exists but not a directory
- error processing file
- failed to copy to
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)