Skip to content

The output structures of rootDir and rootDirs are inconsistent #61883

Closed as not planned

Description

🔎 Search Terms

rootDirs rootDir inconsistent structure

Maybe related to #44321 and #22039.

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about rootDirs (of which there are none). I tried next, 5.8.3 and 2.0.8. All exhibit this behaviour.

⏯ Playground Link

Here's a tiny repo or see below.

💻 Code

tsconfig1.json:

{"compilerOptions": {"outDir": "build", "rootDir": "src"}

tsconfig2.json:

{"compilerOptions": {"outDir": "build", "rootDirs": ["src"]}

src/foo/bar.ts is an empty file.

🙁 Actual behavior

Building with "rootDir": "src" and rootDirs: ["src"] produces different output:

$ tsc -p tsconfig1.json
$ find build/ -type f
build/foo/bar.js
$ rm -r build/
$ tsc -p tsconfig2.json
$ find build/ -type f
build/bar.js

🙂 Expected behavior

Both should do the same thing. Indeed, according to the documentation, using rootDirs ‘does not affect how TypeScript emits JavaScript’.

Additional information about the issue

For single-element arrays, of course, it doesn't really matter. But as it stands, I can't see a way to get both the non-nested structure rootDir provides and multiple root directories. #22039 perhaps suggests that setting both rootDir and rootDirs would work, but doing that makes tsc complain about whichever of rootDirs isn't in rootDir.

Activity

  1. RyanCavanaugh commented on Jun 17, 2025

    @RyanCavanaugh
    Member

    Confusingly, these settings are for basically completely unrelated behaviors, and are not expected to do the same thing.

    rootDir determines what base directory is used to compute the output path. So if you have a file src/foo/bar/baz.ts and set rootDir to src/foo, the output path will be bar/baz.js

    rootDirs is a set of directories to start relative module resolution from.

  2. typescript-bot commented on Jun 20, 2025

    @typescript-bot
    Contributor

    This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  3. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions