{"record":{"id":"f9334d5d521e8bd1","repo":"facebook/react","slug":"the-source-map-has-more-mappings-than-there-are-li","errorCode":null,"errorMessage":"The source map has more mappings than there are lines.","messagePattern":"The source map has more mappings than there are lines\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-esm/src/ReactFlightESMNodeLoader.js","lineNumber":364,"sourceCode":"          exportedEntries[nextEntryIdx].originalColumn = lastOriginalColumn;\n          exportedEntries[nextEntryIdx].originalSource = lastSourceIndex;\n          exportedEntries[nextEntryIdx].nameIndex = lastNameIndex;\n        }\n      }\n\n      for (\n        let lastIdx = mappings.length - 1;\n        lastIdx >= 0 && mappings[lastIdx] === ';';\n        lastIdx--\n      ) {\n        // If the last mapped lines don't contain any segments, we don't get a callback from readMappings\n        // so we need to pad the number of mapped lines, with one for each empty line.\n        lastMappedLine++;\n      }\n\n      sourceLineCount = program.loc.end.line;\n      if (sourceLineCount < lastMappedLine) {\n        throw new Error(\n          'The source map has more mappings than there are lines.',\n        );\n      }\n      // If the original source string had more lines than there are mappings in the source map.\n      // Add some extra padding of unmapped lines so that any lines that we add line up.\n      for (\n        let extraLines = sourceLineCount - lastMappedLine;\n        extraLines > 0;\n        extraLines--\n      ) {\n        mappings += ';';\n      }\n    } else {\n      // If a file doesn't have a source map then we generate a blank source map that just\n      // contains the original content and segments pointing to the original lines.\n      sourceLineCount = 1;\n      let idx = -1;\n      while ((idx = source.indexOf('\\n', idx + 1)) !== -1) {","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server-dom-esm/src/ReactFlightESMNodeLoader.js#L346-L382","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Regenerate source maps for the offending module so source and map come from the same build step","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","If the module needs no mappings, disable source maps for it or strip its sourceMappingURL comment","Clear stale build caches (babel-loader cacheDirectory, turbopack, docker layers) after upgrading the dependency"],"exampleFix":"// before (webpack chain that mutates lines after map generation)\n{ test: /\\.js$/, use: ['my-line-stripping-loader', 'babel-loader'] } // stale map\n\n// after (compose maps through the chain)\n{ test: /\\.js$/, use: ['my-line-stripping-loader?sourceMap', 'babel-loader'] }\n// or rebuild the dependency so its shipped .map matches: npm rebuild <pkg>","handlingStrategy":"validation","validationCode":"// pre-check a module's source map before feeding it through the RSC loader\nfunction mapIsConsistent(source: string, mappings: string): boolean {\n  const lineCount = source.split('\\n').length;\n  let lastIdx = mappings.length - 1;\n  let mappedLines = 0;\n  while (lastIdx >= 0 && mappings[lastIdx] === ';') { mappedLines++; lastIdx--; }\n  // count mapped lines conservatively: semicolon-delimited groups + trailing padding\n  const groups = mappings.split(';').length;\n  return Math.max(groups, mappedLines) <= lineCount + 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await transformModuleWithRscLoader(url, source, map);\n} catch (e) {\n  if (e instanceof Error && e.message === 'The source map has more mappings than there are lines.') {\n    // drop the stale map and retry unmapped, or rebuild the module\n    await transformModuleWithRscLoader(url, source, null);\n  } else throw e;\n}","preventionTips":["Regenerate source maps in the same build step that produces the code","Compose maps through every transform in the chain instead of leaving stale ones","Strip sourceMappingURL from third-party files whose maps you cannot trust before RSC transforms"],"tags":["source-maps","react-server-components","node-loader","build-tooling"],"backgroundTag":"source-map-mismatch","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}