{"id":"a52d9d52c5927b35","repo":"gohugoio/hugo","slug":"failed-to-compile-cache-buster-target-q-w","errorCode":null,"errorMessage":"failed to compile cache buster target %q: %w","messagePattern":"failed to compile cache buster target %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/commonConfig.go","lineNumber":436,"sourceCode":"\t\tm := sourceRe.FindStringSubmatch(s)\n\t\tmatchString := \"no match\"\n\t\tmatch := m != nil\n\t\tif match {\n\t\t\tmatchString = \"match!\"\n\t\t}\n\t\tdebugl.Logf(\"Matching %q with source %q: %s\", s, source, matchString)\n\t\tif !match {\n\t\t\treturn nil\n\t\t}\n\t\tgroups := m[1:]\n\t\tcurrentTarget := target\n\t\t// Replace $1, $2 etc. in target.\n\t\tfor i, g := range groups {\n\t\t\tcurrentTarget = strings.ReplaceAll(target, fmt.Sprintf(\"$%d\", i+1), g)\n\t\t}\n\t\ttargetRe, err := regexp.Compile(currentTarget)\n\t\tif err != nil {\n\t\t\tcompileErr = fmt.Errorf(\"failed to compile cache buster target %q: %w\", currentTarget, err)\n\t\t\treturn nil\n\t\t}\n\t\treturn func(ss string) bool {\n\t\t\tmatch := targetRe.MatchString(ss)\n\t\t\tmatchString := \"no match\"\n\t\t\tif match {\n\t\t\t\tmatchString = \"match!\"\n\t\t\t}\n\t\t\tlogger.Debugf(\"Matching %q with target %q: %s\", ss, currentTarget, matchString)\n\n\t\t\treturn match\n\t\t}\n\t}\n\treturn compileErr\n}\n\nfunc (r Redirect) IsZero() bool {\n\treturn r.From == \"\" && r.FromRe == \"\"","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/config/commonConfig.go#L418-L454","documentation":"Raised inside the compiled cache-buster matcher when the `target` pattern — after substituting `$1`, `$2`... capture groups from the source match — fails regexp.Compile. Unlike the source pattern, the target is compiled lazily per match because it depends on the matched groups, so this error can appear mid-build when a matching file changes, not at config load.","triggerScenarios":"A `[[build.cachebusters]]` `target` that is invalid RE2 on its own (e.g. unclosed group), or that becomes invalid after group substitution — e.g. the source captures a path fragment containing regexp metacharacters like `(` or `[`, and the substituted `$1` yields a broken pattern.","commonSituations":"Filenames or asset paths containing regexp special characters flowing into `$1` substitution; hand-written target regexps with typos that only surface when the source first matches during `hugo server` watch rebuilds; confusion that target is a regexp, not a literal replacement string.","solutions":["Fix the `target` regexp quoted in the error (the message shows the post-substitution pattern) so it compiles as RE2.","If captured groups can contain regexp metacharacters, tighten the source capture group (e.g. `([\\w-]+)`) so substituted values are regexp-safe.","Test by touching a file matching the source pattern under `hugo server` and confirming the rebuild succeeds."],"exampleFix":"# before (hugo.toml)\n[[build.cachebusters]]\nsource = 'assets/js/(.*)\\.js$'\ntarget = '$1\\.(js'\n\n# after\n[[build.cachebusters]]\nsource = 'assets/js/([\\w-]+)\\.js$'\ntarget = '$1\\.js'","handlingStrategy":"validation","validationCode":"for _, cb := range cfg.Build.CacheBusters {\n    if cb.Target != \"\" {\n        if _, err := regexp.Compile(cb.Target); err != nil {\n            return fmt.Errorf(\"build.cachebusters target %q: %w\", cb.Target, err)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := buildCfg.CompileConfig(logger); err != nil {\n    // \"failed to compile cache buster target\" — the 'target' regexp (possibly built from $1 capture substitution) is invalid\n    return err\n}","preventionTips":["`target` is also a regexp, and Hugo substitutes capture groups from `source` into it — a `$1` that expands to regexp metacharacters can break compilation","Keep capture groups in `source` matching only safe token characters (e.g. `([\\w-]+)`) when referenced in `target`","Test source+target as a pair against real file paths, not in isolation"],"tags":["hugo","config","regexp","cache-buster","build","runtime"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}