evanw/esbuild · error · Error
Missing "kind" in () call
Error message
Missing "kind" in ${callName}() call What it means
The options object passed to formatMessages() must include `kind` set to 'error' or 'warning' so esbuild knows how to format the messages. At lib/shared/common.ts:798 the call throws if `kind` is undefined; a further check at line 799 rejects any other string value.
Solutions
- Add `kind: 'error'` or `kind: 'warning'` to the options object.
- Derive kind from the source: use 'error' for result.errors and 'warning' for result.warnings.
Example fix
// before
const out = await esbuild.formatMessages(result.errors, { color: true })
// after
const out = await esbuild.formatMessages(result.errors, { kind: 'error', color: true }) Defensive patterns
Strategy: validation
Validate before calling
function safeFormatMessages(msgs, opts) {
const kind = opts?.kind === 'error' || opts?.kind === 'warning'
? opts.kind
: undefined
if (!kind) throw new Error('formatMessages requires options.kind = "error" | "warning"')
return esbuild.formatMessages(msgs, { ...opts, kind })
}
await safeFormatMessages(result.errors, { color: true }) Type guard
function isFormatKind(v): v is 'error' | 'warning' {
return v === 'error' || v === 'warning'
} Prevention
- Always set options.kind explicitly to 'error' or 'warning'.
- Use a wrapper that derives kind from the message source (errors vs warnings).
- Treat the options object as required, not optional.
When it happens
Trigger: Calling `formatMessages(msgs, { color: true })`, `formatMessages(msgs, { terminalWidth: 80 })`, or any options object omitting `kind`.
Common situations: Passing only cosmetic options (color/terminalWidth) and forgetting kind; copy-pasting a partial options object.
Related errors
- Missing second argument in
- The input to "transform" must be a string or a Uint8Array
- Duplicated test name
- Expected onEnd() callback in plugin
- Expected onLoad() callback in plugin
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/536769ac201eaf49.
Report an issue: GitHub.
Appendix: source
Thrown at lib/shared/common.ts:798
})
}
}
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)
callback(null, response!.messages)
})
}
let analyzeMetafile: StreamService['analyzeMetafile'] = ({ callName, refs, metafile, options, callback }) => {
if (options === void 0) options = {}
let keys: OptionKeys = {}View on GitHub (pinned to f6058f8364)