Source maps and how it works
Your production JavaScript is minified. Variable names are gone. Line numbers are meaningless. When a bug hits production, the stack trace points to line ...
14 Oct 2023

Your production JavaScript is minified. Variable names are gone. Line numbers are meaningless. When a bug hits production, the stack trace points to line 1, column 48293 of app.min.js.
Source maps fix this. They're a mapping file that connects the minified code back to your original source. Your browser's dev tools read this file and show you the real code when debugging.
Enabling source maps with Webpack
Set devtool: "source-map" in your Webpack config. Webpack generates a .map file alongside your bundle and adds a sourceMappingURL comment to the minified output:
// webpack.config.js
module.exports = {
// ...
entry: {
"app": "src/app.js"
},
output: {
path: path.join(__dirname, 'dist'),
filename: "[name].js",
sourceMapFilename: "[name].js.map"
},
devtool: "source-map"
// ...
}
The trade-off
Source maps make debugging possible. But they also expose your original source code. In production, either serve them only to your error-tracking service (Sentry, Datadog) or don't serve them publicly at all. Most teams upload source maps to their monitoring tool and exclude them from the public build.
AI Transformation for Organisational Leaders
For directors, heads of function and founders: eight live evening sessions with Ehsan Gazar and Anoosh Zeighami, ending with a one-page 2027 AI plan for your organisation, built on a real workflow and ready for your leadership team.
$1,495, or $1,045 with code EARLYBIRD until 23 Oct.
View the live cohortKeep reading
- TypeScript Anti-Patterns That Cost You Twice: Build Time, Runtime, and the Interview
- The Frontend Toolchain Is Now Written in Rust and Go. What That Means for You
- oxlint vs ESLint: Why I Replaced ESLint with oxlint
- SystemJS Is Dead. Native ESM Finally Won.
- Replace Axios with a Simple Custom Fetch Wrapper (Production-Ready Guide)
- Stop Shipping ChatGPT Wrappers. Ship an Agent in TypeScript, or Don't Bother.