Typescript: tsc --build with rootDir and outDir is compiling files within a project in alphabetical order, breaking imports

Created on 23 Jul 2018  路  9Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.1.0-dev.20180721


Search Terms: tsc build project reference rootDir outDir

Code

Brief summary: When rootDir and outDir are involved as well as a project reference, source files within an individual project that has a dependency project would be compiled in alphabetical order. The consequence is that an A.ts that imports from B.ts will fail with Output file '.../B.d.ts' has not been built from source file '.../B.ts' but if I rename A.ts to C.ts everything works, as does removing the project reference or not using root/outDir.

The setup is hard to fully convey through text so here's a zip: repro.zip. npm install then npm run build to trigger the issue.

Expected behavior: Compiles both main and other projects successfully regardless of the names of the source files.

Actual behavior:

error TS6305: Output file '.../B.d.ts' has not been built from source file '.../B.ts'.

Bug Fixed

Most helpful comment

I had the same problem but it stopped when I took care of the following. (I'm on v3.8.3 btw).

  • If I ever deleted the outDir I also deleted the generated .tsbuildinfo file too.

    • To exacerbate the situation, the .tsbuildinfo files were created where I would not expect, not in the same folder where the tsconfig.json lives. I didn't catch it because it was gitignored. Regardless, manually setting the "tsBuildInfoFile" compiler option on all my tsconfig files solved that issue.

  • Set the paths compilerOption to the emitted files of any dependencies.

My tsconfigs look like this:

{
  "compilerOptions": {
    "rootDir": "./src",
    "outDir": "./dist/lib",
    "composite": true,
    "baseUrl": "../",
    "paths": {
      "my-dependency": [
        "./my-dependency/dist/lib/index"
      ],
      "my-dependency/*": [
        "./my-dependency/dist/lib/index/*"
      ]
    },
    "tsBuildInfoFile": "tsconfig.tsbuildinfo"
  },
  "include": ["src"],
  "exclude": [
    "**/*.test.ts",
    "**/*.test.tsx"
  ],
  "references": [
    {
      "path": "../my-dependency/tsconfig.json"
    }
  ]
}

All 9 comments

I was just hit by this as well - exact same issue, and the reproduction is bang on what I'm seeing. Let me know if there's anything I can do to help expedite this (PR, tests, another repro, test a beta, etc.). Thanks!

This is broken in 3.8.0-beta

This is broken. Again.

Version 3.7.5 and 3.7.4.

This is broken in 3.7.5

the same in 3.7.2

I had the same problem but it stopped when I took care of the following. (I'm on v3.8.3 btw).

  • If I ever deleted the outDir I also deleted the generated .tsbuildinfo file too.

    • To exacerbate the situation, the .tsbuildinfo files were created where I would not expect, not in the same folder where the tsconfig.json lives. I didn't catch it because it was gitignored. Regardless, manually setting the "tsBuildInfoFile" compiler option on all my tsconfig files solved that issue.

  • Set the paths compilerOption to the emitted files of any dependencies.

My tsconfigs look like this:

{
  "compilerOptions": {
    "rootDir": "./src",
    "outDir": "./dist/lib",
    "composite": true,
    "baseUrl": "../",
    "paths": {
      "my-dependency": [
        "./my-dependency/dist/lib/index"
      ],
      "my-dependency/*": [
        "./my-dependency/dist/lib/index/*"
      ]
    },
    "tsBuildInfoFile": "tsconfig.tsbuildinfo"
  },
  "include": ["src"],
  "exclude": [
    "**/*.test.ts",
    "**/*.test.tsx"
  ],
  "references": [
    {
      "path": "../my-dependency/tsconfig.json"
    }
  ]
}

I am on 3.9.3 and the bug is still there... @sheetalkamat

This breaks the project references feature and makes it entirely unusable.

@desmap you would need to open new issue with exact repro steps to be able to investigate this. The repro in this issue seems to be working correctly.

@sheetalkamat Unfortunately I'm not in a position to set up a repro project, but in my case, this is happening when the build script is running within a docker image build. I assume it has to do with the way the output file is compared with an existing tsbuildinfo file that has been copied or volume mounted. That's speculative, so I'll try to get an exact answer once I work around the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  路  3Comments

wmaurer picture wmaurer  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments

seanzer picture seanzer  路  3Comments

manekinekko picture manekinekko  路  3Comments