Skip to content
jshacks.dev
Debugging

Map minified code back with source maps

Show original TypeScript lines in stack traces with node --enable-source-maps and a tsc sourceMap build, instead of line numbers from compiled JavaScript.

1 min read
Summarize in AI

A stack trace points at dist/app.js:14, a line of compiled output you never wrote. A source map links that line back to your original file, and Node.js can use it when asked.

src/app.tsTypeScript
function main() {
  throw new Error("boom");
}

try {
  main();
} catch (err) {
  console.log((err as Error).stack);
}
Shell
npx tsc --sourceMap --outDir dist src/app.ts
node --enable-source-maps dist/app.js
Text
Error: boom
    at main (/app/src/app.ts:2:9)
    at Object.<anonymous> (/app/src/app.ts:6:3)

The compiler writes dist/app.js.map, and the flag makes Node.js read it when it builds the stack, so the frames show src/app.ts with the right line and column. Node.js prints a few internal frames after these, which are left out here. See the [--enable-source-maps flag](https://nodejs.org/api/cli.html#--enable-source-maps).

Without the flag, the same run reports the compiled dist/app.js lines. Browsers do the same mapping in DevTools when a .map file is reachable.

The flag adds some overhead when errors are created, so it is best for development and for services where you want readable traces. Keep the maps next to the build, or upload them to your error tracker.

Share

More snippets

Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read
Debugging

Inspect an object with console.dir

Show nested objects beyond the default depth of two with console.dir and the depth option, instead of the [Object] placeholders console.log prints.

1 min read
Debugging

Debug a single Vitest test in VS Code

Run one Vitest file under the VS Code debugger with a launch configuration that passes the open file, so breakpoints in tests and source work. Vitest 3.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.