vercel/next.js · error
Source at index ${sourceIndex} not found
Error message
Source at index ${sourceIndex} not found What it means
Thrown by computeTreemapLayoutFromAnalyzeInternal when analyzeData.source(sourceIndex) returns undefined, meaning the source index is out of bounds for the analyze header's sources array (analyze-data.ts:240 just does sources[index]). It is an internal-consistency error: the treemap traversal (either the root index passed to computeTreemapLayoutFromAnalyze or a child index returned by sourceChildren) referenced a source that does not exist in the loaded analyze data. In a well-formed analyze report this never happens, so hitting it indicates a corrupt/mismatched @next/analyze report or an out-of-band index computed elsewhere.
Source
Thrown at apps/bundle-analyzer/lib/treemap-layout.ts:119
for (const rootIdx of roots) {
processDirectory(rootIdx)
}
return metadata
}
// Internal function that uses precomputed metadata
function computeTreemapLayoutFromAnalyzeInternal(
analyzeData: AnalyzeData,
sourceIndex: SourceIndex,
foldedPath: string,
rect: LayoutRect,
metadata: SourceMetadata[],
sizeMode: SizeMode
): LayoutNode {
const source = analyzeData.source(sourceIndex)
if (!source) {
throw new Error(`Source at index ${sourceIndex} not found`)
}
const isDirectory = source.path.endsWith('/') || !source.path
const childrenIndices = analyzeData.sourceChildren(sourceIndex)
// Fold single-child directories
if (
childrenIndices.length === 1 &&
isDirectory &&
(foldedPath + source.path).length <= 40
) {
const childIndex = childrenIndices[0]
const child = analyzeData.source(childIndex)
if (child?.path.endsWith('/')) {
return computeTreemapLayoutFromAnalyzeInternal(
analyzeData,
childIndex,View on GitHub (pinned to 0ae8c72462)
Solutions
- Regenerate the analyze report with the matching bundle-analyzer version (re-run the build's analyze step) so the tree structure and sources list agree.
- Before computing the layout, guard the requested sourceIndex against analyzeData.sourceCount() and the children indices against the same bound; surface a clearer error about which index is stale.
- If consuming reports from multiple sources, validate the analyze header once on load (sources length, every child index < sources.length) instead of letting the layout crash deep in recursion.
- If you built AnalyzeData by hand, audit the code that fills analyzeHeader.sources and the parent->child index maps for off-by-one or stale-reference bugs.
Example fix
// before
const root = computeTreemapLayoutFromAnalyze(analyzeData, requestedIndex, rect, filter, sizeMode)
// after
if (requestedIndex < 0 || requestedIndex >= analyzeData.sourceCount()) {
throw new Error(
`sourceIndex ${requestedIndex} out of range [0, ${analyzeData.sourceCount()})`
)
}
const root = computeTreemapLayoutFromAnalyze(analyzeData, requestedIndex, rect, filter, sizeMode) Defensive patterns
Strategy: validation
Validate before calling
function isValidSourceIndex(analyzeData: AnalyzeData, idx: number): boolean {
return Number.isInteger(idx) && idx >= 0 && idx < analyzeData.sourceCount()
}
// before computing any layout:
const roots = analyzeData.sourceRoots()
for (const r of roots) {
if (!isValidSourceIndex(analyzeData, r)) throw new Error(`stale root index ${r}`)
for (const c of analyzeData.sourceChildren(r)) {
if (!isValidSourceIndex(analyzeData, c)) throw new Error(`stale child ${c} of root ${r}`)
}
} Type guard
function isAnalyzable(data: AnalyzeData, idx: number): data is AnalyzeData & { sourceIndex: number } {
return data.source(idx) !== undefined
} Try / catch
try {
return computeTreemapLayoutFromAnalyze(analyzeData, sourceIndex, rect, filter, sizeMode)
} catch (err) {
if (err instanceof Error && err.message.startsWith('Source at index')) {
// regenerate the report rather than render a half-broken treemap
throw new Error('Analyze report is inconsistent — regenerate it with the matching analyzer version', { cause: err })
}
throw err
} Prevention
- Always produce and consume analyze reports with the same bundle-analyzer / webpack-bundle-analyzer version.
- Validate the analyze header once on load: sources length > 0 and every child/root index in bounds.
- Don't reuse a sourceIndex across reloads of the report — re-resolve via getSourceIndexFromPath.
- Treat this error as a data-integrity bug, not a user input error; never silently swallow it.
When it happens
Trigger: Calling computeTreemapLayoutFromAnalyze (treemap-layout.ts:271) with a sourceIndex >= analyzeData.sourceCount(), or a child index returned by analyzeData.sourceChildren(idx) that points past the end of the sources array. Also reachable via the single-child directory fold at lines 127-144 and the recursive children walk at 247-256 when the analyze header's tree links are inconsistent with its sources list.
Common situations: Loading an analyze report produced by a different/older @next/build-analyzer or webpack-bundle-analyzer plugin version whose tree format differs; manually constructing or hand-editing an AnalyzeData instance and passing a stale sourceIndex; a partial/truncated report JSON where the sources array was cut off but child references remained.
Related errors
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/3c10ac35b87f646c.
Report an issue: GitHub.