gohugoio/hugo · error

failed to create config

Error message

failed to create config: %w

What it means

The non-module branch: when no module config files were merged, LoadConfig still calls configs.transientErr() as a safety check. If any per-language Config carries a transient error from the first decode pass, it is wrapped and returned here. Functionally the no-modules twin of error 270.

Solutions

  1. Read the wrapped transient error for the specific language and cause.
  2. Fix the named field; if the message is opaque, simplify config and bisect.

Example fix

// resolve the named per-language field per the wrapped error message
// no generic before/after applies
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := allconfig.LoadConfig(d); err != nil {
    // message: failed to create config: <transient>
    return err
}

Prevention

When it happens

Trigger: A single-language or no-theme project where the first decode pass tolerated a deferred error that transientErr now escalates.

Common situations: Edge-case config that decodes but is internally inconsistent; rarely hit in practice because most issues fail decode outright (error 267).

Related errors


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

Appendix: source

Thrown at config/allconfig/load.go:93

	moduleConfig, modulesClient, err := l.loadModules(configs, d.IgnoreModuleDoesNotExist)
	if err != nil {
		return nil, fmt.Errorf("failed to load modules: %w", err)
	}

	if len(l.ModulesConfigFiles) > 0 {
		// Config merged in from modules.
		// Re-read the config.
		configs, err = fromLoadConfigResult(d.Fs, d.Logger, res)
		if err != nil {
			return nil, fmt.Errorf("failed to create config from modules config: %w", err)
		}
		if err := configs.transientErr(); err != nil {
			return nil, fmt.Errorf("failed to create config from modules config: %w", err)
		}
		configs.LoadingInfo.ConfigFiles = append(configs.LoadingInfo.ConfigFiles, l.ModulesConfigFiles...)
	} else if err := configs.transientErr(); err != nil {
		return nil, fmt.Errorf("failed to create config: %w", err)
	}

	configs.Modules = moduleConfig.AllModules
	configs.ModulesClient = modulesClient

	if !d.SkipNpmCheck && npm.NpmPackNeedsUpdate(d.Fs, configs.Modules) {
		d.Logger.Warnln(`npm dependencies are out of sync, please run "hugo mod npm pack" (you may also want to run "npm install" after that)`)
	}

	if err := configs.Init(d.Fs, d.Logger); err != nil {
		return nil, fmt.Errorf("failed to init config: %w", err)
	}

	loggers.SetGlobalLogger(d.Logger)

	return
}

View on GitHub (pinned to 52c9bd7908)