evanw/esbuild · error · Error

Expected ${quote(key)} in mangle cache to map to either a st

Error message

Expected ${quote(key)} in mangle cache to map to either a string or false

What it means

Error "Expected ${quote(key)} in mangle cache to map to either a string or false" thrown in evanw/esbuild.

Source

Thrown at lib/shared/common.ts:118

  return {
    wasmURL,
    wasmModule,
    worker,
  }
}

type MangleCache = Record<string, string | false>

function validateMangleCache(mangleCache: MangleCache | undefined): MangleCache | undefined {
  let validated: MangleCache | undefined
  if (mangleCache !== undefined) {
    validated = Object.create(null) as MangleCache
    for (let key in mangleCache) {
      let value = mangleCache[key]
      if (typeof value === 'string' || value === false) {
        validated[key] = value
      } else {
        throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`)
      }
    }
  }
  return validated
}

type CommonOptions = types.BuildOptions | types.TransformOptions

function pushLogFlags(flags: string[], options: CommonOptions, keys: OptionKeys, isTTY: boolean, logLevelDefault: types.LogLevel): void {
  let color = getFlag(options, keys, 'color', mustBeBoolean)
  let logLevel = getFlag(options, keys, 'logLevel', mustBeString)
  let logLimit = getFlag(options, keys, 'logLimit', mustBeInteger)

  if (color !== void 0) flags.push(`--color=${color}`)
  else if (isTTY) flags.push(`--color=true`); // This is needed to fix "execFileSync" which buffers stderr
  flags.push(`--log-level=${logLevel || logLevelDefault}`)
  flags.push(`--log-limit=${logLimit || 0}`)
}

View on GitHub (pinned to 6ff1d8b0d8)

Solutions

  1. Ensure each mangle cache value is either a string (the renamed identifier) or false (to disable renaming)
  2. Fix any values in the mangle cache that are numbers, objects, or other types

Example fix

esbuild.buildSync({ mangleCache: { oldName: 'newName', keepName: false } });

When it happens

Trigger: Thrown at lib/shared/common.ts:118 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/05bbc67946998c36.json. Report an issue: GitHub.