Course contentsShow
← React
Lesson 1334 of 2,39633. Error BoundariesFree lesson

Source Maps for Readable Stack Traces

Upload source maps to your error tracker so minified production errors show original file names and line numbers.

Source Maps for Readable Stack Traces

What you'll learn: How to upload source maps to error trackers so production errors reveal actual file names and line numbers instead of minified gibberish.

When React apps build for production, they're minified and bundled—all your readable code becomes compressed into files like main.abc123.js. When errors happen in production, stack traces look like at n (main.abc123.js:1:4523). Good luck debugging that.

Source maps are special files that map minified code back to your original source. They let error tracking services like Sentry translate cryptic production errors into readable stack traces showing your actual component names, file paths, and line numbers.

Why This Matters

Without source maps, a production error might show:

TypeError: Cannot read property 'name' of undefined
  at n (main.abc123.js:1:4523)

With source maps uploaded to your error tracker:

TypeError: Cannot read property 'name' of undefined
  at UserProfile (src/components/UserProfile.jsx:42:18)

Same error, but now you know exactly where to look.

How It Works

Build tools generate .map files alongside your bundles. You upload these to your error tracking service (usually during CI/CD), but never serve them publicly. When an error occurs, the service uses your uploaded maps to decode the stack trace server-side.

Most build tools generate source maps automatically in production with devtool: 'source-map' (Webpack) or sourcemap: true (Vite). Then use your error tracker's CLI or plugin to upload them during deployment.

Key Takeaway: Upload source maps to your error tracking service so production errors show your actual source code locations—debugging becomes possible instead of guesswork. Keep the maps private; only your error service needs them.