gohugoio/hugo · error

Unable to locate config file or config directory. Perhaps…

Error message

Unable to locate config file or config directory. Perhaps you need to create a new project.
Run `hugo help new` for details.

What it means

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.

Solutions

  1. Run `hugo new site .` (or create a hugo.toml) to initialise a project
  2. cd into the project root that contains hugo.toml/yaml/json
  3. Verify any --config paths exist and are readable

Example fix

# before
hugo          # in a non-project dir
# after
hugo new site . --force && hugo
Defensive patterns

Strategy: validation

Validate before calling

if len(conf.configs.LoadingInfo.ConfigFiles) == 0 {
    return errors.New("no config found; run `hugo new site`")
}

Prevention

When it happens

Trigger: 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.

Common situations: Not in a Hugo project directory; wrong cwd; typo in --config; fresh checkout missing a generated config.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/87019212fe2e1766. Report an issue: GitHub.

Appendix: source

Thrown at commands/hugobuilder.go:1103

	// We need to set the environment as early as possible because we need it to load the correct config.
	c.r.resolveEnvironment(c.s != nil)
	cfg.Set("environment", c.r.environment)

	cfg.Set("internal", hmaps.Params{
		"running":        running,
		"watch":          watch,
		"verbose":        c.r.isVerbose(),
		"fastRenderMode": c.fastRenderMode,
	})

	conf, err := c.r.ConfigFromProvider(configKey{counter: c.r.configVersionID.Load()}, flagsToCfg(cd, cfg))
	if err != nil {
		return err
	}

	if len(conf.configs.LoadingInfo.ConfigFiles) == 0 {
		//lint:ignore ST1005 end user message.
		return errors.New("Unable to locate config file or config directory. Perhaps you need to create a new project.\nRun `hugo help new` for details.")
	}

	c.conf = conf
	c.confOld = conf
	if c.onConfigLoaded != nil {
		if err := c.onConfigLoaded(false); err != nil {
			return err
		}
	}

	return nil
}

var rebuildCounter atomic.Uint64

func (c *hugoBuilder) printChangeDetected(typ string) {
	msg := "\nChange"
	if typ != "" {

View on GitHub (pinned to 52c9bd7908)