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 · 1 min read

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.
Ehsan Gazar helps software engineers take LLM and agent systems from demo to production. He writes about building LLM systems that hold up in production: evals, tracing, RAG, agent architecture and cost control. He teaches the Senior to Staff AI Engineer cohort on Maven, where engineers learn to design and defend these systems.
Forward Deployed AI Engineering: From Customer Problem to Production Value
A live Maven cohort for engineers: 10 live 90-minute sessions taking one AI engagement from customer problem to production, ending with eight artefacts and a working slice in your own repo.
January cohort starts Tue 12 Jan 2027, Tue & Thu 6:30pm London. Enrolling now, 20 seats, $1,800.
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.