TypeScript Compiler Options

sourceRoot — TypeScript compiler option

Sets the sourceRoot value used by source-map consumers to resolve original source locations. It does not upload source files or change where TypeScript reads them. Use with source maps; ensure the advertised source location matches the deployment. The example URL is intentionally non-resolving and is not contacted. Default: unset. Create the named files in a clean local project. Run tsc -p tsconfig.json. Expected output files: dist/example.js, dist/example.js.map. Run node dist/example.js; expected stdout: '3'. Tested using TypeScript 5.8.3 and Node.js 22.16.0; local project instructions, not a single-file editor.

Formal Syntax & Structure

typescript syntaxtypescript
{  "compilerOptions": {    "sourceRoot": "https://example.invalid/sources/"  }}

Parameters & Attributes

NameTypeDescription
sourceRootsource location stringSet in compilerOptions; default: unset.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "noEmitOnError": true,    "outDir": "dist",    "sourceMap": true,    "sourceRoot": "https://example.invalid/sources/"  },  "files": [    "example.ts"  ]}// File: example.tsexport const count: number = 3;console.log(count);
TypeScript Reference