'typescript outDir setting in tsconfig.json not working
I can't seem to get the outDir flag working when used in package.json. Directory structure is pretty simple: tsconfig.json at the root level, together with a src/ directory and a single index.ts file plus other directories representing other modules.
When running the tsc command on the index file, it creates a new one beside it instead of in the build directory. What am I doing wrong?
My tsconfig:
{
"compilerOptions": {
"outDir": "build"
}
}
My npm build script:
"build": "tsc src/index.ts"
I'm calling the script from the root dir of the project. Interestingly, running the same script with an --outDir flag works just fine.
Solution 1:[1]
In my case it was being ignored because I had noEmit: true in tsconfig.json. For whatever reason, the files still were emitted, but in the same directory instead of following outDir.
The config file was read correctly and this error also appeared when using the flag.
Solution 2:[2]
If you are using the incremental compiler option, you may not be getting output if you have deleted / modified files in your outDir but have not removed the .tsbuildinfo file.
My issue was a bit different, but Google brought me here - so figured others may also.
Solution 3:[3]
This is my folder structure.
Keep the typescript files in src folder and keep the tsconfig.json in root.
In tsconfig json file add foldername for outDir in compilerOptions
"compilerOptions": {
"outDir": "build",
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"sourceMap": true
},
and run the below commands.
just cd to the root folder and type
tsc
or
tsc --outDir .
which will build the outDir folder with js and map.js files.
source: https://github.com/Microsoft/TypeScript/issues/10585
Solution 4:[4]
You need to declare your tsconfig file location instead of the file you want to build.
tsc --build mocks/tsconfig.json
Solution 5:[5]
Make sure "outDir" is defined under "compilerOptions"
I had it defined at the same level as "compilerOptions"
{
"compilerOptions": {
"baseUrl": "node_modules/@types",
"lib": [
"es6"
],
"outDir": "dist",
"esModuleInterop": true,
},
"exclude": [
"node_modules"
],
"include": [
"src/**/*"
],
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | fregante |
| Solution 2 | joshweir |
| Solution 3 | chandoo |
| Solution 4 | Ash Blue |
| Solution 5 | Rohit |


