facebook/react · error · Error

The source map has more mappings than there are lines.

Error message

The source map has more mappings than there are lines.

What it means

When the unbundled Node loader rewrites a 'use client'/'use server' file, it merges the file's existing source map with the new mappings for generated code. It counts the lines covered by the original mappings string (including trailing empty lines) and compares that to the AST's line count (program.loc.end.line). If the map claims more mapped lines than the source actually has, the map does not describe this file, and merging would produce corrupted positions, so the loader throws this invariant.

Source

Thrown at packages/react-server-dom-unbundled/src/ReactFlightUnbundledNodeLoader.js:364

          exportedEntries[nextEntryIdx].originalColumn = lastOriginalColumn;
          exportedEntries[nextEntryIdx].originalSource = lastSourceIndex;
          exportedEntries[nextEntryIdx].nameIndex = lastNameIndex;
        }
      }

      for (
        let lastIdx = mappings.length - 1;
        lastIdx >= 0 && mappings[lastIdx] === ';';
        lastIdx--
      ) {
        // If the last mapped lines don't contain any segments, we don't get a callback from readMappings
        // so we need to pad the number of mapped lines, with one for each empty line.
        lastMappedLine++;
      }

      sourceLineCount = program.loc.end.line;
      if (sourceLineCount < lastMappedLine) {
        throw new Error(
          'The source map has more mappings than there are lines.',
        );
      }
      // If the original source string had more lines than there are mappings in the source map.
      // Add some extra padding of unmapped lines so that any lines that we add line up.
      for (
        let extraLines = sourceLineCount - lastMappedLine;
        extraLines > 0;
        extraLines--
      ) {
        mappings += ';';
      }
    } else {
      // If a file doesn't have a source map then we generate a blank source map that just
      // contains the original content and segments pointing to the original lines.
      sourceLineCount = 1;
      let idx = -1;
      while ((idx = source.indexOf('\n', idx + 1)) !== -1) {

View on GitHub (pinned to eafeac097b)

Solutions

  1. Regenerate the source map for the offending file so it matches the current compiled output (or delete the stale sourceMappingURL comment).
  2. Disable source maps for the intermediate compile step that runs before the RSC loader, letting the loader generate its own blank map.
  3. Fix transform ordering: the map the loader reads must correspond to the exact source text it receives (map of the last transform, not an earlier one).
  4. If the map appears valid, capture the file + map and report it as a bug against react-server-dom-unbundled's loader.

Example fix

// before: stale map shipped alongside edited output
//# sourceMappingURL=app.client.js.map

// after: regenerate map with the build that emits app.client.js, or drop the comment
// (rebuilt: app.client.js + app.client.js.map from the same compiler run)
Defensive patterns

Strategy: fallback

Validate before calling

// Sanity-check a map against its file before the RSC loader sees it
function mapMatchesFile(source, map) {
  const fileLines = source.split('\n').length;
  let mappedLines = map.mappings.split(';').length;
  return mappedLines <= fileLines;
}
if (sourceMap && !mapMatchesFile(source, sourceMap)) {
  sourceMap = null; // drop stale map, let the loader generate a blank one
}

Try / catch

try {
  await import('./view.client');
} catch (e) {
  if (/source map has more mappings than there are lines/.test(String(e.message))) {
    // rebuild the file's sourcemap or compile without maps
    console.error('Sourcemap out of sync for', e.moduleName || 'module');
  }
  throw e;
}

Prevention

When it happens

Trigger: Loading a 'use client' or 'use server' module through the RSC Node loader whose sourceMappingURL points at a map with more mapping lines than the file has lines — a stale, mismatched, or mis-chained map from a previous transform.

Common situations: Compiled output paired with a stale map after the source was edited; a transform chain (e.g. another Babel/SWC pass) emitting a map for a different stage of the file; inline sourcemaps from concatenated bundles; files with CRLF/encoding oddities after map generation.

Related errors


AI-assisted analysis of facebook/react@eafeac097b (2026-08-21). Data as JSON: /api/errors/69e0716365b19bdc. Report an issue: GitHub.