evanw/esbuild · error · Error

Failed to find "${id}" in output

Error message

Failed to find "${id}" in output

What it means

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.

Source

Thrown at scripts/verify-source-map.js:834

    }

    if (isStdin) {
      outCode = stdout
      recordCheck(outCode.includes(`# sourceMappingURL=data:application/json;base64,`), `stdin must contain source map`)
      outCodeMap = Buffer.from(outCode.slice(outCode.indexOf('base64,') + 'base64,'.length).trim(), 'base64').toString()
    }

    else {
      outCode = await fs.readFile(path.join(tempDir, outfile), 'utf8')
      recordCheck(outCode.includes(`# sourceMappingURL=${encodeURIComponent(outfile)}.map`), `${outfile} file must link to ${outfile}.map`)
      outCodeMap = await fs.readFile(path.join(tempDir, `${outfile}.map`), 'utf8')
    }

    // Check the mapping of various key locations back to the original source
    const checkMap = (out, map) => {
      for (const id in toSearch) {
        const outIndex = out.indexOf(`"${id}"`)
        if (outIndex < 0) throw new Error(`Failed to find "${id}" in output`)
        const outLines = out.slice(0, outIndex).split('\n')
        const outLine = outLines.length
        const outLastLine = outLines[outLines.length - 1]
        let outColumn = outLastLine.length
        const { source, line, column } = map.originalPositionFor({ line: outLine, column: outColumn })

        const inSource = isStdin ? '<stdin>' : toSearch[id]
        recordCheck(decodeURI(source) === inSource, `expected source: ${inSource}, observed source: ${source}`)

        const inCode = map.sourceContentFor(source)
        if (inCode === null) throw new Error(`Got null for source content for "${source}"`)
        let inIndex = inCode.indexOf(`"${id}"`)
        if (inIndex < 0) inIndex = inCode.indexOf(`'${id}'`)
        if (inIndex < 0) throw new Error(`Failed to find "${id}" in input`)
        const inLines = inCode.slice(0, inIndex).split('\n')
        const inLine = inLines.length
        const inLastLine = inLines[inLines.length - 1]
        let inColumn = inLastLine.length

View on GitHub (pinned to f6058f8364)

Solutions

  1. Open the generated output file and confirm whether the identifier is genuinely absent (renamed/mangled/removed).
  2. 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.
  3. If the absence is a bug, fix the transform so the identifier is preserved as expected.

Example fix

// before (toSearch id is mangled away in output)
const toSearch = { longName: 'in.js' }

// after (pick an identifier that survives, or disable mangling)
const toSearch = { keep: 'in.js' }
Defensive patterns

Strategy: validation

Validate before calling

function allIdsPresentInOutput(toSearch, output) {
  const missing = Object.keys(toSearch).filter(id => output.indexOf(`"${id}"`) < 0);
  return missing.length === 0 ? null : missing;
}

Try / catch

try { checkMap(outCode, outMap); }
catch (e) {
  if (/Failed to find .* in output/.test(e.message)) console.error('Identifier missing from generated output (renamed/mangled/removed):', e.message);
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09). Data as JSON: /api/errors/5b3a5d30cccfe586. Report an issue: GitHub.