Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rosslovas opened this issue Jul 23, 2018 · 10 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@rosslovas
Copy link

rosslovas commented Jul 23, 2018

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

@hwillson
Copy link

hwillson commented Aug 2, 2018

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!

@rifler
Copy link

rifler commented Jan 16, 2020

This is broken in 3.8.0-beta

@resynth1943
Copy link

resynth1943 commented Feb 14, 2020

This is broken. Again.

Version 3.7.5 and 3.7.4.

@theseyi
Copy link

theseyi commented Feb 25, 2020

This is broken in 3.7.5

@dmtrrk
Copy link

dmtrrk commented Feb 27, 2020

the same in 3.7.2

@sparebytes
Copy link

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"
    }
  ]
}

@desmap
Copy link

desmap commented Jul 14, 2020

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

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

@sheetalkamat
Copy link
Member

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

@joelday
Copy link
Contributor

joelday commented Jul 16, 2020

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

@fabiancook
Copy link
Contributor

#25864 (comment)

Can a resolution of this to be not to use tsbuildinfo if the outDir doesn't exist?

SgtPooki added a commit to ipfs-shipyard/js-pinning-service-http-client that referenced this issue Apr 1, 2022
Currently only working after a successful run of 'npm run clean && npm install && npm run build'

but if you remove the dist folder and then try to build again, tsc -b doesn't build deps in order. seems similar to microsoft/TypeScript#25864
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests