TypeScript Reference ยท tsconfig: Language, Modules and Emit Options
TypeScript sourceMap and inlineSourceMap options
Reference for sourceMap, inlineSourceMap and inlineSources: how maps connect JavaScript back to TypeScript lines, and how to get readable stack traces.
A source map is a small file that links each position in the compiled JavaScript back to the TypeScript that produced it. Debuggers, browser dev tools and Node use it so breakpoints and stack traces show app.ts:12 instead of a line in generated code.
sourceMap writes the map as a separate .js.map file and adds a //# sourceMappingURL= comment to the JavaScript. inlineSourceMap embeds the map in the .js file itself as a base64 data: URL. Use one or the other, not both.
{ "compilerOptions": { "sourceMap": true, "inlineSources": true } }
Try it
This site compiles main.ts with source maps and runs Node with --enable-source-maps, so error locations refer to your TypeScript lines. You can check that from inside the program.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
{ "compilerOptions": { "sourceMap": true, "inlineSourceMap": false, "inlineSources": true, "sourceRoot": "", "mapRoot": "" } }
| Name | Description |
|---|---|
sourceMap |
Emit a .js.map file per output file. |
inlineSourceMap |
Embed the map in the .js file as a data URL. Cannot be combined with sourceMap. |
inlineSources |
Put the original TypeScript text into the map, so debuggers work without the .ts files on disk. Needs a map option. |
sourceRoot |
Location prefix for the sources, if debuggers should look elsewhere. |
mapRoot |
Location prefix for map files, for hosting them on another server. |
Usage notes
- Node only reads maps when started with
--enable-source-maps(orprocess.setSourceMapsEnabled(true)); otherwise stack traces show the generated lines. - Maps make output bigger or add files; many teams ship them to an error-tracking service rather than to every user.
declarationMapis separate: it maps.d.tsfiles back to source for editor navigation.- A bundler produces its own maps; if you use one, enable maps there and let
tscrun withnoEmit. - Inline maps are convenient for tests and scripts, but bloat files meant for production.