evanw/esbuild · error · LexerPanic
Invalid binding pattern
Error message
Invalid binding pattern
What it means
Once esbuild decides a parenthesized expression is an arrow function, it validates the parameter bindings. If the collected binding tokens were not legal bindings (invalidLog.invalidTokens is non-empty), it logs 'Invalid binding pattern' for each offending token and aborts.
Source
Thrown at internal/js_parser/js_parser.go:3304
}
}
// Arrow function parsing may be forced if this parenthesized expression
// was prefixed by a TypeScript type parameter list such as "<T,>()"
if isArrowFn || opts.forceArrowFn {
if commaAfterSpread.Start != 0 {
p.log.AddError(&p.tracker, logger.Range{Loc: commaAfterSpread, Len: 1}, "Unexpected \",\" after rest pattern")
}
p.logArrowArgErrors(&arrowArgErrors)
p.logDeferredArrowArgErrors(&errors)
// Now that we've decided we're an arrow function, report binding pattern
// conversion errors
if len(invalidLog.invalidTokens) > 0 {
for _, token := range invalidLog.invalidTokens {
p.log.AddError(&p.tracker, token, "Invalid binding pattern")
}
panic(js_lexer.LexerPanic{})
}
// Also report syntax features used in bindings
for _, entry := range invalidLog.syntaxFeatures {
p.markSyntaxFeature(entry.feature, entry.token)
}
arrow := p.parseArrowBody(args, fnOrArrowDataParse{
needsAsyncLoc: loc,
await: await,
})
arrow.IsAsync = isAsync
arrow.HasRestArg = spreadRange.Len > 0
p.popScope()
return js_ast.Expr{Loc: loc, Data: arrow}
}
}
View on GitHub (pinned to f6058f8364)
Solutions
- Correct the destructuring pattern to use valid property names and commas.
- Remove stray tokens/operators from the parameter list.
- If the code is TypeScript, ensure the .ts/.tsx loader is used so types parse.
Example fix
// before
const f = ({a-b}) => a
// after
const f = ({a, b}) => a Defensive patterns
Strategy: validation
Validate before calling
import "github.com/evanw/esbuild/pkg/api"
res := api.Transform(src, api.TransformOptions{Loader: api.LoaderTS})
for _, m := range res.Errors {
if strings.Contains(m.Text, "Invalid binding pattern") {
// m.Location is the bad token in the arrow parameter list
}
} Prevention
- Type-check arrow parameters with tsc; destructuring key names must be valid identifiers.
- Use the .ts/.tsx loader for TypeScript so annotations are parsed, not treated as invalid bindings.
- Lint destructuring patterns for stray tokens.
When it happens
Trigger: Arrow parameters that are not valid destructuring/identifier bindings, e.g. '({a-b}) => {}', '(123) => {}', or a stray ':'/operator inside the parameter list.
Common situations: Malformed destructuring in arrow params; leftover TypeScript annotation parsed as JS (wrong loader); partial edits leaving stray tokens.
Related errors
- Unexpected newline before "=>"
- Unexpected ":"
- Unexpected "..."
- Unexpected "," after rest pattern
- For loop initializers cannot start with "async of"
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/43345eee88f6430b.
Report an issue: GitHub.