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

The RSC ESM Node loader rewrites modules to register server/client references while preserving source maps. After reading a module's existing source map, it counts mapped lines by scanning trailing ';' separators in the mappings string (plus padding for unmapped trailing lines) and compares that count with program.loc.end.line from parsing the transformed source. If the map claims more mapped lines than the file actually contains, it throws rather than emit a corrupt source map for the rewritten module.

Source

Thrown at packages/react-server-dom-esm/src/ReactFlightESMNodeLoader.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 source maps for the offending module so source and map come from the same build step
  2. Make each transform in the chain compose its source map (babel sourceMaps: true, postcss/webpack source-map chaining) instead of leaving a stale map in place
  3. If the module needs no mappings, disable source maps for it or strip its sourceMappingURL comment
  4. Clear stale build caches (babel-loader cacheDirectory, turbopack, docker layers) after upgrading the dependency

Example fix

// before (webpack chain that mutates lines after map generation)
{ test: /\.js$/, use: ['my-line-stripping-loader', 'babel-loader'] } // stale map

// after (compose maps through the chain)
{ test: /\.js$/, use: ['my-line-stripping-loader?sourceMap', 'babel-loader'] }
// or rebuild the dependency so its shipped .map matches: npm rebuild <pkg>
Defensive patterns

Strategy: validation

Validate before calling

// pre-check a module's source map before feeding it through the RSC loader
function mapIsConsistent(source: string, mappings: string): boolean {
  const lineCount = source.split('\n').length;
  let lastIdx = mappings.length - 1;
  let mappedLines = 0;
  while (lastIdx >= 0 && mappings[lastIdx] === ';') { mappedLines++; lastIdx--; }
  // count mapped lines conservatively: semicolon-delimited groups + trailing padding
  const groups = mappings.split(';').length;
  return Math.max(groups, mappedLines) <= lineCount + 1;
}

Try / catch

try {
  await transformModuleWithRscLoader(url, source, map);
} catch (e) {
  if (e instanceof Error && e.message === 'The source map has more mappings than there are lines.') {
    // drop the stale map and retry unmapped, or rebuild the module
    await transformModuleWithRscLoader(url, source, null);
  } else throw e;
}

Prevention

When it happens

Trigger: A module whose source map does not match the code being transformed: the file was minified, stripped, or rewritten after its map was generated; an inline sourceMappingURL pointing at a map for a previous version of the file (stale cache); an earlier transform in the loader/bundler chain changed line counts without composing its own map into the chain.

Common situations: Transpiled packages in node_modules shipped with stale .map files; build pipelines that append banners or remove lines after source-map generation; babel-loader/turbo/docker caches serving a mismatched source+map pair after a dependency upgrade.

Related errors


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