{"id":"b4dfcd3fc423140d","repo":"gohugoio/hugo","slug":"could-not-determine-content-directory-for-q","errorCode":null,"errorMessage":"could not determine content directory for %q","messagePattern":"could not determine content directory for %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/filesystems/basefs.go","lineNumber":210,"sourceCode":"\n\t}\n\n\tif !isAbs {\n\t\t// A filename on the form \"posts/mypage.md\", put it inside\n\t\t// the first content folder, usually <workDir>/content.\n\t\t// Pick the first project dir (which is probably the most important one).\n\t\tfor _, dir := range b.SourceFilesystems.Content.mounts() {\n\t\t\tif !dir.IsDir() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tmeta := dir.Meta()\n\t\t\tif meta.IsProject {\n\t\t\t\treturn filename, filepath.Join(meta.Filename, filename), nil\n\t\t\t}\n\t\t}\n\t}\n\n\treturn \"\", \"\", fmt.Errorf(\"could not determine content directory for %q\", filename)\n}\n\n// ResolveJSConfigFile resolves the JS-related config file to a absolute\n// filename. One example of such would be postcss.config.js.\nfunc (b *BaseFs) ResolveJSConfigFile(name string) string {\n\t// First look in assets/_jsconfig\n\tfi, err := b.Assets.Fs.Stat(filepath.Join(files.FolderJSConfig, name))\n\tif err == nil {\n\t\treturn fi.(hugofs.FileMetaInfo).Meta().Filename\n\t}\n\t// Fall back to the work dir.\n\tfi, err = b.Work.Stat(name)\n\tif err == nil {\n\t\treturn fi.(hugofs.FileMetaInfo).Meta().Filename\n\t}\n\n\treturn \"\"\n}","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/filesystems/basefs.go#L192-L228","documentation":"`BaseFs.AbsProjectContentDir` maps a content filename (as given to `hugo new`) to an absolute path inside one of the project's content mounts. If the name doesn't fall under any configured content mount and no project-owned content directory exists to place it in, Hugo cannot decide where the file belongs and returns this error.","triggerScenarios":"Running `hugo new content posts/my-page.md` (or the archetype machinery) when the resolved path matches no content mount: the `content` directory is missing, all content mounts come from themes/modules (none has `IsProject`), or an absolute/target path lies outside every configured `[[module.mounts]]` source for the content component.","commonSituations":"Running `hugo new` from the wrong working directory (not the site root); a config using `[[module.mounts]]` that remaps content but forgets a project-level content mount; brand-new sites where `content/` was never created; `contentDir` pointing at a non-existent path.","solutions":["Run the command from the site root and ensure the `content/` directory (or your configured `contentDir`) exists — `mkdir content` fixes the fresh-site case.","If you use `[[module.mounts]]`, add a project mount with `source = \"content\"` and `target = \"content\"` so there's a project content dir to receive new files.","Pass a path that resolves inside an existing content mount, e.g. `hugo new content posts/first.md` rather than an absolute path outside the project."],"exampleFix":"# before (hugo.toml with custom mounts, no project content mount)\n[[module.mounts]]\nsource = \"themes/x/content\"\ntarget = \"content\"\n# after\n[[module.mounts]]\nsource = \"content\"\ntarget = \"content\"\n[[module.mounts]]\nsource = \"themes/x/content\"\ntarget = \"content\"","handlingStrategy":"validation","validationCode":"# Verify the target directory maps into a configured content mount:\nhugo config mounts | jq '.[] | select(.target|startswith(\"content\"))'\n# Ensure the path you create/reference lives under one of those source dirs","typeGuard":null,"tryCatchPattern":"if err := createContent(path); err != nil {\n    return fmt.Errorf(\"path %q is outside all content mounts — add a [[module.mounts]] entry or use contentDir: %w\", path, err)\n}","preventionTips":["When using module mounts, ensure every content path you write to is covered by a mount targeting content","Use `hugo new` with paths relative to the content dir, not absolute filesystem paths","After editing [[module.mounts]], run `hugo config mounts` to confirm the mapping","Don't mix a custom contentDir with mounts unless both are declared"],"tags":["hugo","filesystem","mounts","hugo-new"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}