TypeScript Reference ยท tsconfig: Language, Modules and Emit Options
TypeScript outDir and outFile options
Reference for outDir and outFile: where tsc writes compiled files, how rootDir shapes the folder layout, and why a bundler usually replaces outFile.
outDir is the folder where the compiler writes everything it emits: .js files, and also .d.ts, .map and .tsbuildinfo files when those are enabled. Without it, every output file lands next to its source file, which clutters the source tree and makes .gitignore rules awkward.
The folder structure inside outDir mirrors the source tree, measured from rootDir. outFile is the older sibling: it concatenates all output into a single file, but it only works with a few module formats and is deprecated in recent compilers, so use a bundler for single-file output.
{ "compilerOptions": { "rootDir": "src", "outDir": "dist" } }
Try it
You cannot see tsc write files in this page, but you can model the mapping it uses. The rule is: take the path relative to rootDir, swap the extension, and put it under outDir.
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.
The second result shows the classic surprise: add one file outside src and the inferred root becomes the project folder, so output moves from dist/index.js to dist/src/index.js. Set rootDir explicitly to avoid it.
Syntax
{ "compilerOptions": { "rootDir": "src", "outDir": "dist", "outFile": "dist/bundle.js" } }
| Name | Description |
|---|---|
outDir |
A folder path (relative to the tsconfig). Created if missing. |
rootDir |
The folder that maps to the top of outDir. If a source file lies outside it, the compiler reports an error (TS6059). |
outFile |
A single output file. Allowed only with module set to a format that supports bundling, so it is no use for Node ES modules or CommonJS. |
Usage notes
- Put
outDirin.gitignore, and exclude it fromincludeso compiled.d.tsfiles are never read back as input. outDiris ignored undernoEmit.- Declaration files follow
declarationDirif set, otherwiseoutDir. - For single-file bundles, use esbuild, Rollup, Vite or similar and let TypeScript only type-check (
noEmit). - When files are emitted next to the source (no
outDir), a later compile may pick up the generated.jsas input ifallowJsis on. - Never point
outDirat a source folder.