{"record":{"id":"8c6629c654105fac","repo":"gohugoio/hugo","slug":"unable-to-locate-config-file-or-config-directory-8c6629","errorCode":null,"errorMessage":"Unable to locate config file or config directory. Perhaps you need to create a new project.\n       Run `hugo help new` for details.\n","messagePattern":"Unable to locate config file or config directory\\. Perhaps you need to create a new project\\.\n       Run `hugo help new` for details\\.\n","errorType":"validation","errorClass":"ErrNoConfigFile","httpStatus":null,"severity":"critical","filePath":"config/allconfig/load.go","lineNumber":43,"sourceCode":"\t\"github.com/gobwas/glob\"\n\t\"github.com/gohugoio/hugo/common/herrors\"\n\t\"github.com/gohugoio/hugo/common/hexec\"\n\t\"github.com/gohugoio/hugo/common/hmaps\"\n\t\"github.com/gohugoio/hugo/common/hugo\"\n\t\"github.com/gohugoio/hugo/common/loggers\"\n\t\"github.com/gohugoio/hugo/common/paths\"\n\t\"github.com/gohugoio/hugo/common/types\"\n\t\"github.com/gohugoio/hugo/config\"\n\t\"github.com/gohugoio/hugo/helpers\"\n\thglob \"github.com/gohugoio/hugo/hugofs/hglob\"\n\t\"github.com/gohugoio/hugo/modules\"\n\t\"github.com/gohugoio/hugo/modules/npm\"\n\t\"github.com/gohugoio/hugo/parser/metadecoders\"\n\t\"github.com/spf13/afero\"\n)\n\n//lint:ignore ST1005 end user message.\nvar ErrNoConfigFile = errors.New(\"Unable to locate config file or config directory. Perhaps you need to create a new project.\\n       Run `hugo help new` for details.\\n\")\n\nfunc LoadConfig(d ConfigSourceDescriptor) (configs *Configs, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"failed to load config: %v\", r)\n\t\t\tdebug.PrintStack()\n\t\t}\n\t}()\n\n\tif len(d.Environ) == 0 && !hugo.IsRunningAsTest() {\n\t\td.Environ = os.Environ()\n\t}\n\n\tif d.Logger == nil {\n\t\td.Logger = loggers.NewDefault()\n\t}\n\n\tl := &configLoader{ConfigSourceDescriptor: d, cfg: config.New()}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/config/allconfig/load.go#L25-L61","documentation":"Hugo could not locate any configuration file. loadConfig returns ErrNoConfigFile when, after checking the explicit --config path (if given) and the default names (hugo.toml/yaml/json etc.), no file is found. Without a config file Hugo cannot bootstrap a site.","triggerScenarios":"Running `hugo` in a directory with no config file, or passing --config pointing at a nonexistent path; the default config name search finds nothing.","commonSituations":"Running from the wrong directory (not the project root); a freshly cloned empty repo before scaffolding; a typo in the --config flag value.","solutions":["Create a project with `hugo new site .` (or add a hugo.toml).","Change to the directory that contains hugo.toml before running hugo.","Pass a correct, existing --config path."],"exampleFix":"// before\nhugo              # no config in cwd\n// after\nhugo new site .\nhugo server","handlingStrategy":"validation","validationCode":"// Check for a default config file before invoking Hugo\nnames := []string{\"hugo.toml\", \"hugo.yaml\", \"hugo.json\", \"config.toml\"}\nfound := false\nfor _, n := range names {\n    if _, err := os.Stat(filepath.Join(workDir, n)); err == nil { found = true; break }\n}\nif !found {\n    return fmt.Errorf(\"no config file found in %s\", workDir)\n}","typeGuard":null,"tryCatchPattern":"if errors.Is(err, allconfig.ErrNoConfigFile) {\n    // guide user to create a project or point --config at the right file\n}","preventionTips":["Run hugo from the project root that holds hugo.toml.","Scaffold with `hugo new site` before first build.","Double-check --config paths for typos."],"tags":["config","hugo","cli","filesystem"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}