Debugging with source maps
Benedikt Meurer
Engineering Lead�@ChromeDevTools
Who debugs code?
Who debugs using source maps?
Who develops with React, Vue, Svelte, Angular, or the like?
Source code
Project tree
Call Stack
Ctrl + Shift + P
Cmd + Shift + P
🤨
😭
🤔
>95%
of y’all are (or in the past have been) debugging with source maps
Source maps are an essential part of web dev now!
👨💻
🖥️
HTML, JS, CSS
👨💻
🖥️
HTML, JS, CSS
👨💻
🖥️
HTML, JS, CSS
Closure, GSS
👨💻
🖥️
HTML, JS, CSS
👨💻
🖥️
HTML, JS, CSS
Closure, GSS
👨💻
🖥️
HTML, JS, CSS
SASS, TS, Svelte
What are source maps anyways?
A source map is a file that maps from the transformed source to the original source. It is a mapping between the generated/transpiled/minified JavaScript file and one or more original source files. The main purpose of Sourcemaps is to aid debugging. If there is an error in the generated code file, the map can tell you the original source file location. That's it. It is pretty powerful in practice!
Benefits of using source maps:
If you are developing JavaScript applications, I recommend using source maps. They can make your life much easier!
Source maps provide point wise mappings
What are source maps, anyways?
const hello = (name) => {
return `Hello ${name}!`;
};
const hello=l=>`Hello ${l}!`;
//# sourceMappingURL=hello.min.js.map
hello.min.js
hello.js
npx terser
What are source maps, anyways?
const hello = (name) => {
return `Hello ${name}!`;
};
const hello=l=>`Hello ${l}!`;
//# sourceMappingURL=hello.min.js.map
hello.min.js
hello.js
npx terser
{� "version":3,
"sources":["hello.js"],
"mappings":"AAAA,MAAM,MAAS,GACN,SAAS"
}
hello.min.js.map
What are source maps, anyways?
{� "version":3,
"sources":["hello.js"],
"mappings":"AAAA,MAAM,MAAS,GACN,SAAS"
}
hello.min.js.map
What are source maps, anyways?
{� "version":3,
"sources":["hello.js"],
"mappings":"AAAA,MAAM,MAAS,GACN,SAAS"
}
hello.min.js.map
What are source maps, anyways?
{� "version":3,
"sources":["hello.js"],
"mappings":[[0,0,0,0],[6,0,0,6], [12,0,0,15],[15,0,1,9], [24,0,1,18]]
}
hello.min.js.map
import {decode}
from '@jridgewell/sourcemap-codec'
decode("AAAA,MAAM,MAAS,GACN,SAAS")
Mappings, explained!
const hello = (name) => {
return `Hello ${name}!`;
};
const hello=l=>`Hello ${l}!`;
//# sourceMappingURL=hello.min.js.map
hello.min.js
hello.js
{� "version":3,
"sources":["hello.js"],
"mappings":[[0,0,0,0],[6,0,0,6], [12,0,0,15],[15,0,1,9], [24,0,1,18]]
}
hello.min.js.map
Extending point-wise mappings to ranges
const hello = (name) => {
return `Hello ${name}!`;
};
const hello=l=>`Hello ${l}!`;
//# sourceMappingURL=hello.min.js.map
hello.min.js
hello.js
{� "version":3,
"sources":["hello.js"],
"mappings":[[0,0,0,0],[6,0,0,6], [12,0,0,15],[15,0,1,9], [24,0,1,18]]
}
hello.min.js.map
Limitations and future directions
Bringing the ecosystem along…