-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Project-references type check with --noEmit fails without built files #40431
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
Comments
A |
@RyanCavanaugh Thanks for the response. This functionality looks like what I want to achieve using If it's true, it means that the mechanism is already in place. It would be great to expose some flags for developers to use it. Please correct me if I confuse two unrelated features. Maybe @sheetalkamat could suggest something regarding use of this functionality via CLI. |
That PR is implemented by presenting the type checker with a virtual file system that builds .d.ts files on the fly; we can't enable it with a flag from |
@valerybugakov Did you ever find a way to solve the problem you've described here? |
@taylorkline, not the root cause. We partially solved the performance issue in our project by caching type check commands per Typescript project with |
I think this issue should be reconsidered, and opened again. It appears that not only do we get Project references are used in the Vite template for React and TypeScript which is very popular. Any execution of In addition, it is not efficient to run EDIT: Here is a reproduction of this issue which I created for the Vitest team. |
I'm confused — so is this a technical limitation (as the first quote implies), or a design/correctness limitation? |
I hope this topic gets revisited in the future. I just ran into this when I explored the idea of using project references to speed up type checking (via |
The thing is that project references put on the table some unique functionality like project boundaries, which can be extra useful in monorepo's workflow,however, it currently overlooks its potential due to the necessity of building files, leading to a performance degradation when compared to the --noEmit check. In the realm of modern monorepo development, there's a shift towards employing rapid compilers like SWC and esbuild with extracting type checking into a separate task. In such approaches, emitting any files through TypeScript (tsc) becomes unnecessary, further enhancing overall efficiency. I would really like to see someday this feature in your roadmap. |
Run into this many times, I believe it should be fixed. There should be no reason to need to emit declaration files if you are just trying to type check and have noEmit set, and the errors are quite confusing. |
This is super annoying! Without using extra tooling, resorting to tsc -b || tsc -b --clean does the job of type-checking without leaving extra files behind. Type checking and building are treated as separate tasks by virtually every project, tsc would better serve users by supporting this flow for project references too. How does VS Code do it? It shows type errors without adding files to the project file tree. Can't that functionality be ported over to tsc? |
The whole point of project references is1 to let one project consume another project's declarations, which is why generating The requirement is enforced by the fact that You may, however, set I am surprised this solution still hasn't been mentioned in this thread. As the TypeScript team does not seem to be willing to implement on-the-fly Footnotes
|
@aweebit outputting .d.ts leads to issues if files are moved, renamed, or deleted between builds. The old .d.ts files remain and result in undetectable errors, like importing from files that should no longer exist. |
mkdir leftover-declarations
cd leftover-declarations
npm init -y
npm pkg set type="module"
npm i -D typescript@~5.7.3
mkdir referenced // tsconfig.referenced.json
{
"include": ["referenced"],
"compilerOptions": {
"outDir": "node_modules/.tmp",
"composite": true,
"emitDeclarationOnly": true
}
} // tsconfig.json
{
"exclude": ["referenced"],
"compilerOptions": {
"outDir": "node_modules/.tmp",
"noEmit": true
},
"references": [
{ "path": "./tsconfig.referenced.json" }
]
} echo "export default 42" > referenced/original.ts
echo "import value from './referenced/original'" > index.ts
npx tsc -b
mv referenced/original.ts referenced/renamed.ts
npx tsc -b This results in
despite So I cannot seem to reproduce the issue you are describing. Could you give a concrete example where leftover declaration files actually lead to problems? |
@aweebit I mostly only uses project references in monorepo setups which is where I see the problem occur often. Run |
A solution that turned out to be wrong:
Update: I've just realized I only thought it worked because I left no exports other than The rest of the original comment: By the way, the article also mentions that you should always put your custom export conditions such as the But it would be even better if there was an option to clean leftover files from the output directory during rebuilds. By that I don't mean something that would have the same effect as |
It turns out there has been an open issue with a similar feature request for almost 8 years now: And I've also found an open issue requesting to support |
For those who received email notifications with my previous comments in their original form: the solution with pnpm's I've just found a different solution on Stack Overflow: https://stackoverflow.com/a/79144361/9861000 It involves an external dependency though, namely Google's Wireit tool. Its About section says:
The docs even have a dedicated TypeScript recipe:
I haven't tried it myself, but looks like exactly what I was looking for. Should be a viable solution for monorepos, although of course it is not cool that a third-party tool is required for something like that. In the answer to the Stack Overflow question, I also found another relevant issue from 2020: Unfortunately, TypeScript team's stance seems to be that the limitation is by design, so for now, it seems like Wireit running in watch mode during development is as good a solution as it gets. |
TypeScript Version: ^4.0.2
Search Terms: "has not been built from source file", "project-references", "typecheck without emit"
Description
In monorepo with project-references it's not possible to use
tsc
for type check only without emitting files.Whereas calling
tsc -b
works without any issues. But there's no point in emitting files if we only need to perform type check of all related modules.It seems that is should be possible because of: #32028
Expected behavior:
tsc
with--noEmit
builds all referenced projects without emitting anything:Actual behavior:
It fails because no built files are found for referenced projects:
Playground Link:
repro repo
git clone https://github.com/valerybugakov/project-references-demo cd ./project-references-demo npm i npm run typecheck
Related Issues:
#25613
#25600
#30661 (comment)
The text was updated successfully, but these errors were encountered: