Course contentsShow
← TypeScript
Lesson 1242 of 1,79629. The Build PipelineFree lesson

Source Maps Across Tools

Configure source maps so debugging works correctly whether using tsc or a bundler's transpiler.

Source Maps Across Tools

What you'll learn: How to configure source maps so your debugging experience stays smooth whether you're using TypeScript's compiler or a bundler like Webpack, esbuild, or Vite.

What Are Source Maps and Why Do Tools Matter?

You've already learned that source maps let you debug your original TypeScript code even after it's been transpiled to JavaScript. But here's the catch: different tools generate source maps differently, and if they're not configured correctly, your debugging setup can break.

Think of source maps like GPS coordinates. When tsc compiles your code, it creates one set of "coordinates" mapping JavaScript back to TypeScript. But when a bundler like Webpack or esbuild transpiles your code, it creates its own coordinates. If these don't align properly, your debugger gets lost.

Configuring Source Maps in tsc

In your tsconfig.json:

{
  "compilerOptions": {
    "sourceMap": true,
    // OR for inline maps:
    "inlineSourceMap": true
  }
}

This generates .map files alongside your .js output when using tsc directly.

Configuring Source Maps in Bundlers

Webpack (with ts-loader or babel):

// webpack.config.js
module.exports = {
  devtool: 'source-map' // or 'inline-source-map' for dev
};

Vite:

// vite.config.js
export default {
  build: {
    sourcemap: true
  }
};

esbuild:

esbuild.build({
  sourcemap: true
});

The Key Insight: Separation of Concerns

Many modern workflows use tsc only for type-checking (tsc --noEmit) while the bundler handles transpilation. In this case:

  • TypeScript doesn't emit source maps (because it doesn't emit anything)
  • The bundler creates source maps for its own transpilation step
  • You configure source maps in the bundler's config, not tsconfig.json

Key Takeaway: Source maps must be configured wherever transpilation happens—if using tsc alone, set sourceMap: true in tsconfig.json; if using a bundler for transpilation, configure source maps in the bundler's settings instead.