gohugoio/hugo · error
babel config %q not found
Error message
babel config %q not found
What it means
When the babel resource transformer resolves its config file, a user-specified config (the transformer's config option) that cannot be resolved to an existing file via BaseFs.ResolveJSConfigFile produces this error. Hugo only fails for explicitly specified configs; auto-detected babel.config.{js,mjs,cjs} that are absent are silently skipped.
Source
Thrown at resources/resource_transformers/babel/babel.go:148
if t.options.Config != "" {
configFile = t.options.Config
} else {
for _, name := range []string{"babel.config.js", "babel.config.mjs", "babel.config.cjs"} {
configFile = t.rs.BaseFs.ResolveJSConfigFile(name)
if configFile != "" {
break
}
}
}
if configFile != "" {
configFile = filepath.Clean(configFile)
// We need an absolute filename to the config file.
if !filepath.IsAbs(configFile) {
configFile = t.rs.BaseFs.ResolveJSConfigFile(configFile)
if configFile == "" && t.options.Config != "" {
// Only fail if the user specified config file is not found.
return fmt.Errorf("babel config %q not found", t.options.Config)
}
}
}
ctx.ReplaceOutPathExtension(".js")
var cmdArgs []any
if configFile != "" {
infol.Logf("use config file %q", configFile)
cmdArgs = []any{"--config-file", configFile}
}
if optArgs := t.options.toArgs(); len(optArgs) > 0 {
cmdArgs = append(cmdArgs, optArgs...)
}
cmdArgs = append(cmdArgs, "--filename="+ctx.SourcePath)
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Fix the path in the babel options to match the actual file, relative to the project root: {{ $js := $src | babel (dict "config" "babel.config.js") }}.
- Place babel.config.js/.mjs/.cjs in the project root and drop the config option entirely — Hugo auto-detects those names.
- If the config lives in a theme/module, ensure it's mounted so ResolveJSConfigFile can find it.
Example fix
<!-- before -->
{{ $js := $src | babel (dict "config" "babel.confg.js") }}
<!-- after -->
{{ $js := $src | babel }} <!-- with babel.config.js in project root --> Defensive patterns
Strategy: validation
Validate before calling
# ensure config exists at project root before invoking test -f babel.config.js || echo 'missing babel.config.js'
Try / catch
{{ with try ($js | babel (dict "config" "babel.config.js")) }}{{ with .Err }}{{ errorf "babel: %s" . }}{{ end }}{{ end }} Prevention
- Place babel.config.js at the project root, or pass the correct `config` option path
- Paths are relative to the project working directory — verify with an absolute path if unsure
- Commit the babel config so CI has it; a local-only config is the classic CI failure
When it happens
Trigger: Calling babel with an options map like (dict "config" "myconfig.js") where that path doesn't exist in the project (or any mounted theme/module filesystem).
Common situations: Typo in the config filename; config file located outside the project root or not mounted via module mounts; renaming .babelrc to babel.config.js but pointing the option at the old name; running from a different working directory in CI.
Related errors
- failed to detect target data serialization format
- unsupported transpiler %q; valid values are %q or %q
- must not provide more arguments than resource object and opt
- 'paginate' configuration setting must be positive to paginat
- markup must not be set, use mediaType
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/9ca610dce89770d8.json.
Report an issue: GitHub ↗.