{"record":{"id":"a7cd5093bf042b67","repo":"gohugoio/hugo","slug":"failed-to-resolve-q-to-an-archetype-template","errorCode":null,"errorMessage":"failed to resolve %q to an archetype template","messagePattern":"failed to resolve %q to an archetype template","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"create/content.go","lineNumber":97,"sourceCode":"\text := paths.Ext(targetPath)\n\n\tb.setArcheTypeFilenameToUse(ext)\n\n\twithBuildLock := func() (string, error) {\n\t\tif !h.Configs.Base.NoBuildLock {\n\t\t\tunlock, err := h.BaseFs.LockBuild()\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"failed to acquire a build lock: %s\", err)\n\t\t\t}\n\t\t\tdefer unlock()\n\t\t}\n\n\t\tif b.isDir {\n\t\t\treturn \"\", b.buildDir()\n\t\t}\n\n\t\tif ext == \"\" {\n\t\t\treturn \"\", fmt.Errorf(\"failed to resolve %q to an archetype template\", targetPath)\n\t\t}\n\n\t\tif !h.Conf.ContentTypes().IsContentFile(b.targetPath) {\n\t\t\treturn \"\", fmt.Errorf(\"target path %q is not a known content format\", b.targetPath)\n\t\t}\n\n\t\treturn b.buildFile()\n\t}\n\n\tfilename, err := withBuildLock()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif filename != \"\" {\n\t\treturn b.openInEditorIfConfigured(filename)\n\t}\n","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/create/content.go#L79-L115","documentation":"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.","triggerScenarios":"Invoking `hugo new posts/myfile` (no extension), or calling NewContent programmatically with a targetPath lacking an extension.","commonSituations":"Forgetting the .md (or .html/.ad/.org) extension when scaffolding content via the CLI; assuming Hugo defaults to markdown.","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."],"exampleFix":"# before\n$ hugo new posts/myfile\n\n# after\n$ hugo new posts/myfile.md","handlingStrategy":"validation","validationCode":"import \"github.com/gohugoio/hugo/common/paths\"\n\nfunc ValidateNewContentPath(targetPath string) error {\n    if paths.Ext(targetPath) == \"\" {\n        return fmt.Errorf(\"target path %q has no extension; cannot resolve an archetype\", targetPath)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := create.NewContent(h, kind, targetPath, force); err != nil {\n    return err\n}","preventionTips":["Always include a content extension when invoking `hugo new`.","In scripts, assert the path has a non-empty extension before calling NewContent."],"tags":["content","archetype","cli"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}