{"record":{"id":"5b3a5d30cccfe586","repo":"evanw/esbuild","slug":"failed-to-find-id-in-output","errorCode":null,"errorMessage":"Failed to find \"${id}\" in output","messagePattern":"Failed to find \"(.+?)\" in output","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/verify-source-map.js","lineNumber":834,"sourceCode":"    }\n\n    if (isStdin) {\n      outCode = stdout\n      recordCheck(outCode.includes(`# sourceMappingURL=data:application/json;base64,`), `stdin must contain source map`)\n      outCodeMap = Buffer.from(outCode.slice(outCode.indexOf('base64,') + 'base64,'.length).trim(), 'base64').toString()\n    }\n\n    else {\n      outCode = await fs.readFile(path.join(tempDir, outfile), 'utf8')\n      recordCheck(outCode.includes(`# sourceMappingURL=${encodeURIComponent(outfile)}.map`), `${outfile} file must link to ${outfile}.map`)\n      outCodeMap = await fs.readFile(path.join(tempDir, `${outfile}.map`), 'utf8')\n    }\n\n    // Check the mapping of various key locations back to the original source\n    const checkMap = (out, map) => {\n      for (const id in toSearch) {\n        const outIndex = out.indexOf(`\"${id}\"`)\n        if (outIndex < 0) throw new Error(`Failed to find \"${id}\" in output`)\n        const outLines = out.slice(0, outIndex).split('\\n')\n        const outLine = outLines.length\n        const outLastLine = outLines[outLines.length - 1]\n        let outColumn = outLastLine.length\n        const { source, line, column } = map.originalPositionFor({ line: outLine, column: outColumn })\n\n        const inSource = isStdin ? '<stdin>' : toSearch[id]\n        recordCheck(decodeURI(source) === inSource, `expected source: ${inSource}, observed source: ${source}`)\n\n        const inCode = map.sourceContentFor(source)\n        if (inCode === null) throw new Error(`Got null for source content for \"${source}\"`)\n        let inIndex = inCode.indexOf(`\"${id}\"`)\n        if (inIndex < 0) inIndex = inCode.indexOf(`'${id}'`)\n        if (inIndex < 0) throw new Error(`Failed to find \"${id}\" in input`)\n        const inLines = inCode.slice(0, inIndex).split('\\n')\n        const inLine = inLines.length\n        const inLastLine = inLines[inLines.length - 1]\n        let inColumn = inLastLine.length","sourceCodeStart":816,"sourceCodeEnd":852,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/scripts/verify-source-map.js#L816-L852","documentation":"Thrown at scripts/verify-source-map.js:834 inside checkMap(). For each identifier in the toSearch table, the harness searches the generated output for the quoted token `\"${id}\"` via indexOf. A negative result means the identifier esbuild should have emitted is absent from the output, so source-map positions for it cannot be validated.","triggerScenarios":"A verify-source-map test case defines a toSearch identifier that esbuild's transform renamed, mangled, tree-shook away, or inlined, so the quoted `\"id\"` no longer appears in the generated code. It can also occur if the output file read failed silently or the wrong outfile was inspected.","commonSituations":"A minification/mangling change strips or renames an identifier the harness expects to find verbatim, or the test's toSearch entry was never actually present in the input.","solutions":["Open the generated output file and confirm whether the identifier is genuinely absent (renamed/mangled/removed).","If esbuild legitimately renamed it, update the toSearch table in the test case to an identifier that survives output, or disable mangling for that test.","If the absence is a bug, fix the transform so the identifier is preserved as expected."],"exampleFix":"// before (toSearch id is mangled away in output)\nconst toSearch = { longName: 'in.js' }\n\n// after (pick an identifier that survives, or disable mangling)\nconst toSearch = { keep: 'in.js' }","handlingStrategy":"validation","validationCode":"function allIdsPresentInOutput(toSearch, output) {\n  const missing = Object.keys(toSearch).filter(id => output.indexOf(`\"${id}\"`) < 0);\n  return missing.length === 0 ? null : missing;\n}","typeGuard":null,"tryCatchPattern":"try { checkMap(outCode, outMap); }\ncatch (e) {\n  if (/Failed to find .* in output/.test(e.message)) console.error('Identifier missing from generated output (renamed/mangled/removed):', e.message);\n  throw e;\n}","preventionTips":["Choose toSearch identifiers that survive esbuild's transform (avoid mangled/short names).","Disable mangling for source-map verification cases where exact names matter.","Confirm each toSearch id actually exists in the generated output before asserting on positions."],"tags":["test-harness","source-map","verification","mangling","validation"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}