TypeScript: tsconfig outDir does not keep directory structure
I’m on version 1.6.2
Using directory structure
- temp
- some
- dir
- foo.ts
- tsconfig.json
and tsconfig.json only contains:
{
"compilerOptions": {
"outDir": "build/"
}
}
than when running tsc inside temp I’m expecting foo.js in path /temp/build/some/dir/foo.js
, it’s actually in /temp/build/foo.js
.
It’s the same result as running tsc --outDir build
with an empty tsconfig, while it should be the same as tsc --rootDir . --outDir build
since “The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project”.
Adding a rootDir
key to the compilerOptions in the json does not seem to help either.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Commits related to this issue
- Add rootDir to compilerOptions Things seems to get strange when you use outDir without rootDir. See https://github.com/Microsoft/TypeScript/issues/5134 Adding rootDir fixes the https://github.com/te... — committed to ddgenome/ts-undefined by deleted user 7 years ago
- Add rootDir to TypeScript compiler options Things seems to get strange when you use outDir without rootDir in the tsconfig.json compilerOptions. See https://github.com/Microsoft/TypeScript/issues/51... — committed to atomist-attic/travis-rugs by deleted user 7 years ago
- Add unit tests, update versions and Travis build Add ability to run unit tests using mocha. This required adding `rootDir` to the tsconfig.json to avoid some randomness in where tsc put the compiled... — committed to atomist-attic/rug-rugs by deleted user 7 years ago
This default to the common path prefix of all the sources behavior is the worst. Removing levels of directory structure should always be something you set on purpose, not a default behavior.
set
"rootDir": "./ts"
instead@craxal use
--rootDir ./
. see https://github.com/Microsoft/TypeScript/wiki/FAQ#why-does---outdir-moves-output-after-adding-a-new-file for more details.Still happening to me in Typescript 2.1.5. This is very, very wrong. Is anyone else still encountering this issue?
outDir
is set to “dist”. The problem magically goes away, however, if I have a Typescript file located directly under “src”:@editedredx but note, that even after the fix #4724, you should use the rootDir option to achieve what you want, because otherwise it defaults to the common path prefix of all the sources.