{"record":{"id":"87019212fe2e1766","repo":"gohugoio/hugo","slug":"unable-to-locate-config-file-or-config-directory","errorCode":null,"errorMessage":"Unable to locate config file or config directory. Perhaps you need to create a new project.\nRun `hugo help new` for details.","messagePattern":"Unable to locate config file or config directory\\. Perhaps you need to create a new project\\.\nRun `hugo help new` for details\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/hugobuilder.go","lineNumber":1103,"sourceCode":"\t// We need to set the environment as early as possible because we need it to load the correct config.\n\tc.r.resolveEnvironment(c.s != nil)\n\tcfg.Set(\"environment\", c.r.environment)\n\n\tcfg.Set(\"internal\", hmaps.Params{\n\t\t\"running\":        running,\n\t\t\"watch\":          watch,\n\t\t\"verbose\":        c.r.isVerbose(),\n\t\t\"fastRenderMode\": c.fastRenderMode,\n\t})\n\n\tconf, err := c.r.ConfigFromProvider(configKey{counter: c.r.configVersionID.Load()}, flagsToCfg(cd, cfg))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif len(conf.configs.LoadingInfo.ConfigFiles) == 0 {\n\t\t//lint:ignore ST1005 end user message.\n\t\treturn errors.New(\"Unable to locate config file or config directory. Perhaps you need to create a new project.\\nRun `hugo help new` for details.\")\n\t}\n\n\tc.conf = conf\n\tc.confOld = conf\n\tif c.onConfigLoaded != nil {\n\t\tif err := c.onConfigLoaded(false); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n\nvar rebuildCounter atomic.Uint64\n\nfunc (c *hugoBuilder) printChangeDetected(typ string) {\n\tmsg := \"\\nChange\"\n\tif typ != \"\" {","sourceCodeStart":1085,"sourceCodeEnd":1121,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/hugobuilder.go#L1085-L1121","documentation":"After ConfigFromProvider resolves configuration, if LoadingInfo.ConfigFiles is empty the builder returns this user-facing error: Hugo found no config file (hugo.toml/yaml/json) or config directory in the working directory or supplied paths.","triggerScenarios":"Running hugo/hugo server/hugo build in a directory with no hugo.toml/yaml/json/config dir, or with --config pointing at non-existent files, leaving ConfigFiles empty.","commonSituations":"Not in a Hugo project directory; wrong cwd; typo in --config; fresh checkout missing a generated config.","solutions":["Run `hugo new site .` (or create a hugo.toml) to initialise a project","cd into the project root that contains hugo.toml/yaml/json","Verify any --config paths exist and are readable"],"exampleFix":"# before\nhugo          # in a non-project dir\n# after\nhugo new site . --force && hugo","handlingStrategy":"validation","validationCode":"if len(conf.configs.LoadingInfo.ConfigFiles) == 0 {\n    return errors.New(\"no config found; run `hugo new site`\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run hugo from the project root containing a config file","Validate any --config file existence before invoking hugo"],"tags":["config","hugo","cli","project-init"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}