gohugoio/hugo · error
failed to resolve to an archetype template
Error message
failed to resolve %q to an archetype template
What it means
In create.NewContent (create/content.go:96) Hugo resolves the archetype as <kind><ext> then default<ext>. If the targetPath has no extension, ext (paths.Ext) is the empty string, no archetype filename can be formed, and Hugo cannot scaffold the file. It returns this error instead of guessing a template.
Solutions
- Add a known content extension to the target path (e.g. posts/myfile.md).
- If scripting NewContent, ensure targetPath always ends with a content extension.
Example fix
# before $ hugo new posts/myfile # after $ hugo new posts/myfile.md
Defensive patterns
Strategy: validation
Validate before calling
import "github.com/gohugoio/hugo/common/paths"
func ValidateNewContentPath(targetPath string) error {
if paths.Ext(targetPath) == "" {
return fmt.Errorf("target path %q has no extension; cannot resolve an archetype", targetPath)
}
return nil
} Try / catch
if err := create.NewContent(h, kind, targetPath, force); err != nil {
return err
} Prevention
- Always include a content extension when invoking `hugo new`.
- In scripts, assert the path has a non-empty extension before calling NewContent.
When it happens
Trigger: Invoking `hugo new posts/myfile` (no extension), or calling NewContent programmatically with a targetPath lacking an extension.
Common situations: Forgetting the .md (or .html/.ad/.org) extension when scaffolding content via the CLI; assuming Hugo defaults to markdown.
Related errors
- error processing file
- failed to open non-content file
- no existing content directory configured for this project
- target path is not a known content format
- aborted
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/a7cd5093bf042b67.
Report an issue: GitHub.
Appendix: source
Thrown at create/content.go:97
ext := paths.Ext(targetPath)
b.setArcheTypeFilenameToUse(ext)
withBuildLock := func() (string, error) {
if !h.Configs.Base.NoBuildLock {
unlock, err := h.BaseFs.LockBuild()
if err != nil {
return "", fmt.Errorf("failed to acquire a build lock: %s", err)
}
defer unlock()
}
if b.isDir {
return "", b.buildDir()
}
if ext == "" {
return "", fmt.Errorf("failed to resolve %q to an archetype template", targetPath)
}
if !h.Conf.ContentTypes().IsContentFile(b.targetPath) {
return "", fmt.Errorf("target path %q is not a known content format", b.targetPath)
}
return b.buildFile()
}
filename, err := withBuildLock()
if err != nil {
return err
}
if filename != "" {
return b.openInEditorIfConfigured(filename)
}
View on GitHub (pinned to 52c9bd7908)