{"record":{"id":"9143ed2431a97ded","repo":"evanw/esbuild","slug":"expected-value-for-what-key-void-0","errorCode":null,"errorMessage":"Expected value for ${what}${key !== void 0 ? ' ' + quote(key) : ''} to be a string, got ${typeof value} instead","messagePattern":"Expected value for (.+?)(.+?) to be a string, got (.+?) instead","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/common.ts","lineNumber":142,"sourceCode":"\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}`)\n  if (logStyle) flags.push(`--log-style=${logStyle}`)\n}\n\nfunction validateStringValue(value: unknown, what: string, key?: string): string {\n  if (typeof value !== 'string') {\n    throw new Error(`Expected value for ${what}${key !== void 0 ? ' ' + quote(key) : ''} to be a string, got ${typeof value} instead`)\n  }\n  return value\n}\n\nfunction pushCommonFlags(flags: string[], options: CommonOptions, keys: OptionKeys): void {\n  let legalComments = getFlag(options, keys, 'legalComments', mustBeString)\n  let sourceRoot = getFlag(options, keys, 'sourceRoot', mustBeString)\n  let sourcesContent = getFlag(options, keys, 'sourcesContent', mustBeBoolean)\n  let target = getFlag(options, keys, 'target', mustBeStringOrArrayOfStrings)\n  let format = getFlag(options, keys, 'format', mustBeString)\n  let globalName = getFlag(options, keys, 'globalName', mustBeString)\n  let mangleProps = getFlag(options, keys, 'mangleProps', mustBeRegExp)\n  let reserveProps = getFlag(options, keys, 'reserveProps', mustBeRegExp)\n  let mangleQuoted = getFlag(options, keys, 'mangleQuoted', mustBeBoolean)\n  let minify = getFlag(options, keys, 'minify', mustBeBoolean)\n  let minifySyntax = getFlag(options, keys, 'minifySyntax', mustBeBoolean)\n  let minifyWhitespace = getFlag(options, keys, 'minifyWhitespace', mustBeBoolean)\n  let minifyIdentifiers = getFlag(options, keys, 'minifyIdentifiers', mustBeBoolean)","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/shared/common.ts#L124-L160","documentation":"validateStringValue() at lib/shared/common.ts:140 guards every option value that becomes a `--flag:key=value` CLI token (define, logOverride, alias, banner, footer, loader, outExtension, external, inject, pure, drop, entryPoint values). Each such value must be a JS string; otherwise esbuild throws naming the context (`what`), the key, and the actual typeof it received.","triggerScenarios":"Passing `define: { NODE_ENV: true }`, `loader: { '.css': 1 }`, `external: [/^foo/]`, `pure: [function f(){}]`, or `entryPoints: { app: 42 }`.","commonSituations":"Using a native JS value (boolean, number, regex, function) instead of its string form; loading config from JSON with mixed types; forwarding untyped user input into these keyed maps.","solutions":["Convert the value to a string (e.g. String(value), value.toString(), or regex .source).","For define/replace values that must be string literals in output, wrap in quotes: `\"'production'\"`.","Type the map as Record<string, string> in your own config so non-strings are caught upstream."],"exampleFix":"// before\nawait build({ entryPoints: ['app.ts'], define: { NODE_ENV: true } })\n\n// after\nawait build({ entryPoints: ['app.ts'], define: { NODE_ENV: 'true' } })","handlingStrategy":"type-guard","validationCode":"function assertStringValues(map, name) {\n  if (!map) return map\n  for (const k of Object.keys(map)) {\n    if (typeof map[k] !== 'string') {\n      throw new Error(`${name}[${k}] must be a string, got ${typeof map[k]}`)\n    }\n  }\n  return map\n}\nassertStringValues(options.define, 'define')\nassertStringValues(options.loader, 'loader')","typeGuard":"function isStringRecord(v): v is Record<string, string> {\n  if (!v || typeof v !== 'object') return false\n  return Object.values(v).every(x => typeof x === 'string')\n}\nif (options.define && !isStringRecord(options.define)) {\n  throw new Error('define values must all be strings')\n}","tryCatchPattern":null,"preventionTips":["Type define/loader/alias/banner/footer/outExtension maps as Record<string, string>.","For define values that should be string literals, wrap them in extra quotes.","Coerce regex/function sources with .toString() or .source before placing them in these maps."],"tags":["config","validation","type-mismatch","cli-flags"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}