{"record":{"id":"05bbc67946998c36","repo":"evanw/esbuild","slug":"expected-quote-key-in-mangle-cache-to-map-to-e","errorCode":null,"errorMessage":"Expected ${quote(key)} in mangle cache to map to either a string or false","messagePattern":"Expected (.+?) in mangle cache to map to either a string or false","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/common.ts","lineNumber":118,"sourceCode":"  return {\n    wasmURL,\n    wasmModule,\n    worker,\n  }\n}\n\ntype MangleCache = Record<string, string | false>\n\nfunction validateMangleCache(mangleCache: MangleCache | undefined): MangleCache | undefined {\n  let validated: MangleCache | undefined\n  if (mangleCache !== undefined) {\n    validated = Object.create(null) as MangleCache\n    for (let key in mangleCache) {\n      let value = mangleCache[key]\n      if (typeof value === 'string' || value === false) {\n        validated[key] = value\n      } else {\n        throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`)\n      }\n    }\n  }\n  return validated\n}\n\ntype CommonOptions = types.BuildOptions | types.TransformOptions\n\nfunction pushLogFlags(flags: string[], options: CommonOptions, keys: OptionKeys, isTTY: boolean, logLevelDefault: types.LogLevel): void {\n  let color = getFlag(options, keys, 'color', mustBeBoolean)\n  let logLevel = getFlag(options, keys, 'logLevel', mustBeString)\n  let logLimit = getFlag(options, keys, 'logLimit', mustBeInteger)\n  let logStyle = getFlag(options, keys, 'logStyle', mustBeString)\n\n  if (color !== void 0) flags.push(`--color=${color}`)\n  else if (isTTY) flags.push(`--color=true`); // This is needed to fix \"execFileSync\" which buffers stderr\n  flags.push(`--log-level=${logLevel || logLevelDefault}`)\n  flags.push(`--log-limit=${logLimit || 0}`)","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/shared/common.ts#L100-L136","documentation":"The `mangleCache` option maps property names to either their mangled replacement (a string) or to `false` (meaning 'do not mangle this property'). validateMangleCache() at lib/shared/common.ts:109 rejects any other value type (number, null, true, array, object). This keeps the cache round-trippable between builds.","triggerScenarios":"Passing `mangleCache: { prop: 0 }`, `{ prop: null }`, `{ prop: true }`, or `{ prop: { x: 1 } }` to build()/context()/transform().","commonSituations":"Hand-editing or programmatically transforming a mangleCache returned by a previous build; serializing/deserializing the cache through a layer that coerces booleans; merging caches from multiple sources with non-conforming values.","solutions":["Ensure every value in the mangleCache object is a string or exactly the boolean `false`.","Feed back the mangleCache exactly as esbuild returned it in the previous result.","If you must transform values, coerce to string or `false` explicitly before passing."],"exampleFix":"// before\nawait build({ entryPoints: ['app.ts'], mangleProps: /^_/, mangleCache: { _secret: 0 } })\n\n// after\nawait build({ entryPoints: ['app.ts'], mangleProps: /^_/, mangleCache: { _secret: false } })","handlingStrategy":"validation","validationCode":"function sanitizeMangleCache(cache) {\n  if (!cache) return cache\n  const out = Object.create(null)\n  for (const key of Object.keys(cache)) {\n    const v = cache[key]\n    if (typeof v !== 'string' && v !== false) {\n      throw new Error(`mangleCache[${key}] must be string or false, got ${typeof v}`)\n    }\n    out[key] = v\n  }\n  return out\n}\noptions.mangleCache = sanitizeMangleCache(options.mangleCache)","typeGuard":"function isMangleCache(v): v is Record<string, string | false> {\n  if (!v || typeof v !== 'object') return false\n  return Object.values(v).every(x => typeof x === 'string' || x === false)\n}\nif (options.mangleCache && !isMangleCache(options.mangleCache)) {\n  throw new Error('invalid mangleCache')\n}","tryCatchPattern":null,"preventionTips":["Pass the mangleCache from a previous build result through unchanged.","Type the cache as Record<string, string | false> in your own code.","Validate the cache after JSON round-trips, since those can introduce null/numbers."],"tags":["config","validation","mangle-cache"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}