Glossary

What Is a Source Map? How They Turn Minified Errors Back Into Code

A source map is the JSON file that turns an unreadable minified stack trace back into your real files, lines, and function names. Here is the format, why you must not ship maps publicly, and how the original frame reaches your AI agent.

Hrishikesh BaidyaHrishikesh Baidya7 min read
A tangled block of minified one-line code on the left resolving through a lime decoder lens into a single highlighted original source frame on the right, on a dark canvas

Definition

A source map is a JSON file that maps minified code back to its original source, recovering the real file, line, column, and names. Browsers locate it via a SourceMap HTTP header or a sourceMappingURL comment. The map is never executed; it exists only to make compiled code legible during debugging.

You ship a .js bundle, but you wrote dozens of .tsx and .ts files. A source map is the lookup table that connects the two. The MDN glossary defines it as “a JSON file format that maps between minified or transformed code received by the browser and its original unmodified form,” and notes that browsers find it two ways: a SourceMap HTTP response header, or a //# sourceMappingURL annotation comment at the bottom of the generated file. The map itself is never run. It is metadata that a debugger, an error monitor, or a capture tool reads on demand.

Why a minified stack trace is useless without one

Minification exists for speed: a bundler strips whitespace and comments, renames handleCheckoutSubmit to h, and collapses your whole app onto a handful of very long lines. The browser is happy. Your error reporting is not. When something throws in production, the stack trace points at main.4f3a.js:1:88621: line 1, column 88621, of a file no human ever wrote. You learn that something failed, but not which component, which function, or which of your original lines. The trace has a location in the wrong coordinate system.

A source map fixes exactly that. It converts the generated line:column back into the original file, line, column, and symbol name, so the same failure now reads as Checkout.tsx:88 inside handleCheckoutSubmit. This is not a cosmetic nicety. If you read the companion glossary entry on stack traces, the whole skill of debugging is finding the first frame in your code, and you cannot do that when every frame is a mangled one-character name on line 1. The source map is what makes a minified trace human-readable again.

A diagram showing a minified column coordinate on the left connected by a decoder lens to a single original file, line, and column frame on the right, with a Base64 VLQ ribbon flowing through the lens
A source map decodes one generated column (main.4f3a.js:1:88621) into one original frame (Checkout.tsx:88, handleCheckoutSubmit).

How the mapping actually works

Open a .map file and most of it is a single dense field called mappings. It is encoded as Base64 VLQ (variable-length quantity). According to Polar Signals' teardown of the format, each comma-separated segment holds up to five fields: the generated column, the source-file index, the original line, the original column, and an optional name index. The clever part is that these are stored as relative deltas from the previous segment, not absolute positions. That is why a tiny token like O can encode the number 7 instead of spelling out a full offset such as column 27698. The deltas keep the map small even for a huge bundle.

This format used to be an informal community convention known as “Source Map v3.” As of 2026 it is a real standard. ECMA-426 was published as a 1st-edition Draft on 27 May 2026 by TC39-TG4, formalizing the spec across JavaScript, CSS, and WebAssembly, with the version field still hard-coded to 3 for compatibility. The practical takeaway: a decoder finds the segment that covers the failing generated column, follows its deltas to an absolute original position, and rebuilds the readable frame (file, line, column, and symbol). A plain-language walkthrough of sourcemaps covers the same flow if you want the gentler version.

Do not ship public source maps

Here is the part teams get wrong. Because a source map reconstructs your original, commented source, serving it on the public web hands attackers a copy of your codebase. This is not theoretical. Sentry's security team documented a case where an ethical hacker fetched publicly reachable .map files, reconstructed the minified JavaScript, and recovered hardcoded Stripe secret keys that “permitted unauthorized payments.” The map did not create the secret-in-source mistake, but it made the secret trivially harvestable from the outside.

Generating maps in your build

You almost never write a source map by hand. Your bundler emits one when you ask. The knob is the same idea across tools: turn maps on, and choose whether the browser can find them. For production the safe combination is “generate the file, but hide the pointer,” so the map exists for your tooling to upload privately while no //# sourceMappingURL comment ships to users.

vite.config.jsjavascript
export default {
  build: {
    // true  -> emits .map AND appends the sourceMappingURL comment (avoid in prod)
    // 'hidden' -> emits .map but DROPS the comment, so it is not publicly discoverable
    sourcemap: 'hidden',
  },
};

// webpack equivalent: devtool: 'hidden-source-map'
// tsc:               "sourceMap": true in tsconfig compilerOptions
// esbuild:           --sourcemap=external

After the build, upload the emitted .map files to whatever resolves your frames (an error monitor, for example) as a private artifact, then make sure the raw files are not reachable on your CDN. Most teams add a single edge rule that returns 404 for any *.map request. You keep readable stack traces internally; an outsider hitting your bundle gets nothing to reconstruct.

How this shows up in a real BugMojo bug report

Most articles stop at “upload your map to an error monitor.” Here is what BugMojo does with a stack, and what it does not. BugMojo does not apply source maps. When the browser extension records a console error, an uncaught exception or an unhandled promise rejection during a session, it keeps the stack the browser reported. On a minified production build that stack still points at a coordinate like main.4f3a.js:1:88621, so you resolve it with your private map, in your error monitor or in the checkout where the map was built, to get back to Checkout.tsx:88 and handleCheckoutSubmit. What BugMojo adds is everything else that was happening when it threw.

That “everything else” is the point. The stack ships alongside an rrweb session replay, the full console output, and the network requests around the failure (method, URL, status and timing). Then the BugMojo MCP server hands the whole bundle to an AI agent like Claude Code or Cursor. Resolve the frame with your map and the agent reads the original frame plus the replay and the failing POST /api/cart request, instead of guessing from a mangled column offset. That matters because, in the 2025 Stack Overflow Developer Survey, 66% of developers named dealing with AI solutions that are “almost right, but not quite” their single biggest frustration, and 45% said debugging AI-generated code is more time-consuming. A de-minified frame with state behind it is what keeps an agent from guessing.

FeatureCapabilityBugMojoProd error monitor (Sentry/BugSnag)
De-minifies the frame using your source mapNoNo, it keeps the stack as reportedOn the server, on demand
Keeps the .map private (not public)NoNo map upload neededYes, uploaded privately
rrweb replay + console + network with the frameNoYesBreadcrumbs; Sentry adds Session Replay
Stack and session handed to an AI agent over MCPNoYes, with replay, console and networkSentry has an MCP server
Aggregate uncaught exceptions across a fleetNoNoYes
Long-term production error volume + alertingNoNoYes
Two-sided: BugMojo hands the captured stack and its session to an agent, but it does not apply source maps and it is not a production error monitor.
Hand your agent the stack and the state behind it

BugMojo captures the failing stack with an rrweb replay, console, and network bundle and hands it to Claude Code or Cursor over MCP. Pair it with your source map: readable code in, faster fix out.

See BugMojo for developers

Frequently asked questions

Frequently asked questions

Sources

  1. Source map: MDN Web Docs Glossary (SourceMap header + //# sourceMappingURL detection), MDN / Mozilla (2026)
  2. ECMA-426 Source map format specification: 1st edition Draft, TC39-TG4, Ecma International / TC39 (2026-05-27)
  3. The Inner Workings of JavaScript Source Maps: Base64 VLQ mappings and relative deltas, Polar Signals (2025-11-04)
  4. Abusing Exposed Sourcemaps: Stripe secret keys reconstructed from production .map files, Sentry (Security blog) (2025-01-31)
  5. JavaScript sourcemaps explained, Dimitrios Filippou (2025)
  6. AI: 2025 Stack Overflow Developer Survey ('almost right, but not quite' top frustration, 66%; debugging AI code 45%), Stack Overflow (2025)
  7. Sentry Session Replay: a video-like reproduction of the user's browser, with DOM state, clicks, network requests and console entries, Sentry Docs (checked 26 October 2026)
  8. Sentry MCP server: connects AI assistants to Sentry for searching errors and triaging issues, Sentry (checked 26 October 2026)
Share:

Get bug-tracking insights, weekly.

Engineering deep-dives, QA playbooks, and honest tool comparisons. No spam. Unsubscribe anytime.