evanw/esbuild · error · Error

Missing second argument in

Error message

Missing second argument in ${callName}() call

What it means

formatMessages() requires an options object as its second argument (it must at least contain `kind`). At lib/shared/common.ts:791 esbuild throws if that argument is missing/falsy, before attempting to read any option fields.

Solutions

  1. Pass a second argument with at least `{ kind: 'error' }` or `{ kind: 'warning' }`.
  2. If you have no other preferences, use formatMessages(msgs, { kind: 'error' }).

Example fix

// before
const out = await esbuild.formatMessages(result.warnings)

// after
const out = await esbuild.formatMessages(result.warnings, { kind: 'warning' })
Defensive patterns

Strategy: validation

Validate before calling

function format(msgs, opts) {
  if (!opts) throw new Error('formatMessages requires an options object with kind')
  return esbuild.formatMessages(msgs, opts)
}
await format(result.warnings, { kind: 'warning' })

Prevention

When it happens

Trigger: Calling `formatMessages(msgs)`, `formatMessages(msgs, null)`, or `formatMessages(msgs, undefined)`.

Common situations: Following an older/wrong example; assuming options is optional; destructuring config and passing an undefined variable.

Related errors


AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09). Data as JSON: /api/errors/a3cd13dcf62a7e89. Report an issue: GitHub.

Appendix: source

Thrown at lib/shared/common.ts:791

      } catch (e) {
        let flags: string[] = []
        try { pushLogFlags(flags, options, {}, isTTY, transformLogLevelDefault) } catch { }
        const error = extractErrorMessageV8(e, streamIn, details, void 0, '')
        sendRequest(refs, { command: 'error', flags, error }, () => {
          error.detail = details.load(error.detail)
          callback(failureErrorWithLog('Transform failed', [error], []), null)
        })
      }
    }
    if ((typeof input === 'string' || input instanceof Uint8Array) && input.length > 1024 * 1024) {
      let next = start
      start = () => fs.writeFile(input, next)
    }
    start(null)
  }

  let formatMessages: StreamService['formatMessages'] = ({ callName, refs, messages, options, callback }) => {
    if (!options) throw new Error(`Missing second argument in ${callName}() call`)
    let keys: OptionKeys = {}
    let kind = getFlag(options, keys, 'kind', mustBeString)
    let color = getFlag(options, keys, 'color', mustBeBoolean)
    let terminalWidth = getFlag(options, keys, 'terminalWidth', mustBeInteger)
    let logStyle = getFlag(options, keys, 'logStyle', mustBeString)
    checkForInvalidFlags(options, keys, `in ${callName}() call`)
    if (kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`)
    if (kind !== 'error' && kind !== 'warning') throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`)
    let request: protocol.FormatMsgsRequest = {
      command: 'format-msgs',
      messages: sanitizeMessages(messages, 'messages', null, '', terminalWidth),
      isWarning: kind === 'warning',
    }
    if (color !== void 0) request.color = color
    if (terminalWidth !== void 0) request.terminalWidth = terminalWidth
    if (logStyle !== void 0) request.logStyle = logStyle
    sendRequest<protocol.FormatMsgsRequest, protocol.FormatMsgsResponse>(refs, request, (error, response) => {
      if (error) return callback(new Error(error), null)

View on GitHub (pinned to f6058f8364)