evanw/esbuild · error · Error

Failed to find "${id}" in input

Error message

Failed to find "${id}" in input

What it means

Thrown at scripts/verify-source-map.js:848. Having obtained the original source content via sourceContentFor, the harness searches that text for the quoted token `"id"` (falling back to single-quoted `'id'`). A negative indexOf means the identifier the harness expected to map is not actually present in the original source file, so the original line/column cannot be computed.

Source

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

    // 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

        const expected = JSON.stringify({ source, line: inLine, column: inColumn })
        const observed = JSON.stringify({ source, line, column })
        recordCheck(expected === observed, `expected original position: ${expected}, observed original position: ${observed}`)

        // Also check the reverse mapping
        const positions = map.allGeneratedPositionsFor({ source, line: inLine, column: inColumn })
        recordCheck(positions.length > 0, `expected generated positions: 1, observed generated positions: ${positions.length}`)
        let found = false
        for (const { line, column } of positions) {
          if (line === outLine && column === outColumn) {
            found = true
            break
          }

View on GitHub (pinned to f6058f8364)

Solutions

  1. Open the input source named by toSearch[id] and confirm the identifier exists there in quoted form.
  2. Correct the toSearch entry: fix the identifier spelling, or remap it to the source file that actually contains it.
  3. If the identifier legitimately uses different quoting, ensure the single-quote fallback covers it.

Example fix

// before (id not present in input 'a.js')
const toSearch = { missing: 'a.js' }

// after (point at the file that actually contains the id)
const toSearch = { missing: 'b.js' }
Defensive patterns

Strategy: validation

Validate before calling

function idExistsInSource(inCode, id) {
  return inCode.indexOf(`"${id}"`) >= 0 || inCode.indexOf(`'${id}'`) >= 0;
}

Try / catch

try { checkMap(outCode, outMap); }
catch (e) {
  if (/Failed to find .* in input/.test(e.message)) console.error('toSearch id is not present in its mapped source file:', e.message);
  throw e;
}

Prevention

When it happens

Trigger: A toSearch entry references an identifier that does not exist in the corresponding input source file — a typo in the identifier, a stale toSearch entry after the input was edited, or a mismatch where toSearch maps an id to the wrong source path.

Common situations: A contributor edits an input fixture and removes/renames an identifier but leaves the toSearch table pointing at the old name, or assigns the identifier to the wrong source file.

Related errors


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