{"record":{"id":"306d1a9a1d5a4384","repo":"evanw/esbuild","slug":"s-q-filter-is-not-a-valid-go-regular-expressio","errorCode":null,"errorMessage":"[%s] %q filter is not a valid Go regular expression: %q","messagePattern":"\\[(.+?)\\] %q filter is not a valid Go regular expression: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/config.go","lineNumber":763,"sourceCode":"\n\t// Cache for next time\n\tfilterMutex.Lock()\n\tdefer filterMutex.Unlock()\n\tif filterCache == nil {\n\t\tfilterCache = make(map[string]*regexp.Regexp)\n\t}\n\tfilterCache[filter] = result\n\treturn\n}\n\nfunc CompileFilterForPlugin(pluginName string, kind string, filter string) (*regexp.Regexp, error) {\n\tif filter == \"\" {\n\t\treturn nil, fmt.Errorf(\"[%s] %q is missing a filter\", pluginName, kind)\n\t}\n\n\tresult := compileFilter(filter)\n\tif result == nil {\n\t\treturn nil, fmt.Errorf(\"[%s] %q filter is not a valid Go regular expression: %q\", pluginName, kind, filter)\n\t}\n\n\treturn result, nil\n}\n\nfunc PluginAppliesToPath(path logger.Path, filter *regexp.Regexp, namespace string) bool {\n\treturn (namespace == \"\" || path.Namespace == namespace) && filter.MatchString(path.Text)\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// Plugin API\n\ntype Plugin struct {\n\tName      string\n\tOnStart   []OnStart\n\tOnResolve []OnResolve\n\tOnLoad    []OnLoad\n}","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/config/config.go#L745-L781","documentation":"Thrown when a plugin provides a filter that fails Go's regexp.Compile, meaning it is not valid RE2 regular expression syntax. esbuild uses Go's regexp engine (RE2) which does not support backreferences, lookbehind, or lookahead. The error includes the plugin name, the kind (filter/namespace), and the offending pattern.","triggerScenarios":"Setting a plugin filter to a regex with unsupported syntax such as backreferences (\\1), lookaheads ((?=...)), unbalanced parentheses, or invalid escape sequences.","commonSituations":"Plugin authors familiar with PCRE/JavaScript regex who use features not in RE2 (backreferences, lookahead/lookbehind), or who have a typo like an unescaped special character.","solutions":["Remove RE2-unsupported features: no backreferences (\\1), no lookahead/lookbehind ((?=...), (?<=...))","Validate the pattern with an RE2-compatible tester or Go's regexp.Compile before deploying the plugin","Simplify the regex and test incrementally to isolate the syntax error"],"exampleFix":"// before\nbuild.onResolve({ filter: '\\\\b(foo)\\\\1' }, handler)\n// after\nbuild.onResolve({ filter: '\\\\bfoo' }, handler)","handlingStrategy":"validation","validationCode":"import { RE2 } from 're2-wasm' // or use a Go RE2 reference\nfunction isValidRE2(pattern) {\n  try {\n    new RegExp(pattern) // JS RegExp is close to RE2 for basic patterns\n    return !/\\(\\?.*[=!<>]/.test(pattern) // reject lookahead/lookbehind\n  } catch {\n    return false\n  }\n}\nif (!isValidRE2(filter)) throw new Error(`Filter '${filter}' is not valid RE2`)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember esbuild filters use Go RE2, not JavaScript PCRE — no backreferences or lookahead/lookbehind","Test your regex pattern with Go's regexp package or an RE2 tester before deploying","Keep plugin filters simple and specific to reduce the chance of syntax errors"],"tags":["esbuild","plugin","regex","re2","filter"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}