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

Most upvoted comments

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

Still happening to me in Typescript 2.1.5. This is very, very wrong. Is anyone else still encountering this issue?

  • my-project
    • dist
      • file.js
    • src
      • dir
        • file.ts
    • tsconfig.json

outDir is set to “dist”. The problem magically goes away, however, if I have a Typescript file located directly under “src”:

  • my-project
    • dist
      • dir
        • file.js
      • empty.js
    • src
      • dir
        • file.ts
      • empty.ts
    • tsconfig.json

@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.