gohugoio/hugo · error
babel config not found
Error message
babel config %q not found
What it means
Thrown by the Babel transformer when options.Config is explicitly set by the user (via the babel options 'config' key) but the named file cannot be resolved against the project's JS config file system (BaseFs.ResolveJSConfigFile returns empty). Auto-discovered configs (babel.config.js/mjs/cjs) never trigger this; it fires only for a user-specified config path that is missing.
Solutions
- Verify the file referenced by options["config"] exists; the error message echoes the exact path Hugo could not resolve.
- Use an absolute path or place the config at the project/working-dir root so BaseFs.ResolveJSConfigFile can find it.
- Drop the 'config' option entirely and let Hugo auto-discover babel.config.js / babel.config.mjs / babel.config.cjs.
Example fix
// before
{{ $js := resources.Get "js/main.js" | babel (dict "config" "configs/babel.js") }}
// after
{{ $js := resources.Get "js/main.js" | babel (dict "config" "babel.config.js") }} Defensive patterns
Strategy: validation
Validate before calling
// Validate the user-specified babel config path exists before invoking.
if cfg, ok := opts["config"]; ok {
p := filepath.Clean(fmt.Sprint(cfg))
if _, err := os.Stat(p); err != nil {
return fmt.Errorf("babel config %q not found", p)
}
} Prevention
- Prefer auto-discovered babel.config.js over an explicit 'config' option.
- Version-control your babel config alongside the templates that reference it.
- On case-sensitive OSes, double-check exact filenames of custom config paths.
When it happens
Trigger: Calling resources.Babel with an options map containing "config": "./some/path/babel.config.js" where that path does not exist under the project or asset filesystem, or passing a relative path that BaseFs.ResolveJSConfigFile cannot resolve to an absolute file.
Common situations: Renaming or deleting a custom babel config without updating the babel options in the template; pointing config at a path inside assets/ that has not been created; case-sensitivity mismatch on Linux for a config path copied from macOS/Windows.
Related errors
- postcss config not found
- : failed to transform ( )
- cannot use --renderToMemory with --destination
- cardinalityThreshold threshold must be between 0 and 100
- could not find in the import context
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/9ca610dce89770d8.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)