evanw/esbuild · error · Error

${quote(key)} must be ${mustBe}

Error message

${quote(key)} must be ${mustBe}

What it means

Error "${quote(key)} must be ${mustBe}" thrown in evanw/esbuild.

Source

Thrown at lib/shared/common.ts:82

  typeof value === 'string' || typeof value === 'object' && value !== null && !Array.isArray(value) ? null : 'a string or an object'

let mustBeStringOrArrayOfStrings = (value: string | string[] | undefined): string | null =>
  typeof value === 'string' || (Array.isArray(value) && value.every(x => typeof x === 'string')) ? null : 'a string or an array of strings'

let mustBeStringOrUint8Array = (value: string | Uint8Array | undefined): string | null =>
  typeof value === 'string' || value instanceof Uint8Array ? null : 'a string or a Uint8Array'

let mustBeStringOrURL = (value: string | URL | undefined): string | null =>
  typeof value === 'string' || value instanceof URL ? null : 'a string or a URL'

type OptionKeys = { [key: string]: boolean }

function getFlag<T, K extends (keyof T & string)>(object: T, keys: OptionKeys, key: K, mustBeFn: (value: T[K]) => string | null): T[K] | undefined {
  let value = object[key]
  keys[key + ''] = true
  if (value === undefined) return undefined
  let mustBe = mustBeFn(value)
  if (mustBe !== null) throw new Error(`${quote(key)} must be ${mustBe}`)
  return value
}

function checkForInvalidFlags(object: Object, keys: OptionKeys, where: string): void {
  for (let key in object) {
    if (!(key in keys)) {
      throw new Error(`Invalid option ${where}: ${quote(key)}`)
    }
  }
}

export function validateInitializeOptions(options: types.InitializeOptions): types.InitializeOptions {
  let keys: OptionKeys = Object.create(null)
  let wasmURL = getFlag(options, keys, 'wasmURL', mustBeStringOrURL)
  let wasmModule = getFlag(options, keys, 'wasmModule', mustBeWebAssemblyModule)
  let worker = getFlag(options, keys, 'worker', mustBeBoolean)
  checkForInvalidFlags(options, keys, 'in initialize() call')
  return {

View on GitHub (pinned to 6ff1d8b0d8)

Solutions

  1. Provide the option in the required form stated in the error message
  2. Check the esbuild documentation for the correct value shape for this key

Example fix

// e.g. "outdir" must be a string
esbuild.buildSync({ outdir: 'dist' });

When it happens

Trigger: Thrown at lib/shared/common.ts:82 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of evanw/esbuild@6ff1d8b0d8 (2026-08-03). Data as JSON: /data/errors/a31bb478a51c58a6.json. Report an issue: GitHub.