Skip to content
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

TS build output not invalidated when node_modules changed #38648

Closed
brieb opened this issue May 18, 2020 · 4 comments
Closed

TS build output not invalidated when node_modules changed #38648

brieb opened this issue May 18, 2020 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@brieb
Copy link

brieb commented May 18, 2020

Changes to types within node_modules do not invalidate the TypeScript build output.

Suppose we have a project with project references enabled and that there are no TypeScript errors in the project. If we update our node_modules to a new version of a package that contains types, that could introduce errors into our project. However, if we leave the build output directory in place, we do not see these errors in the tsc -b output.

  1. tsc -b -- no errors.
  2. Update types within node_modules that should trigger error.
  3. tsc -b -- no errors, which is unexpected.

Upon inspection of the tsbuildinfo files, the shas for the node_modules d.ts files do not get updated.

We cache our TS output directory between CI builds so that we can incrementally build from it on subsequent builds. We currently invalidate our cache whenever node_modules changes. Ideally, we could keep the cache and TypeScript could figure out what needs to be recompiled.

Separately, it would be great if the validity rules for the TypeScript output were documented as part of the project references docs. That would help us better understand when it is safe to rebuild from an existing output vs requiring a clean build (between TS versions, when node_modules change, etc).

Thank you! 😃

TypeScript Version: 4.0.0-dev.20200518

Search Terms:
project references, build, incremental, node_modules, invalidate, tsb, tsc -b, rebuild, @types

Code

https://github.com/brieb/ts-issue--tsb-nodemodules

Expected behavior:

TS errors reported when types within node_modules change.

Actual behavior:

No TS errors reported.

Errors only reported after editing code within project triggers invalidation.

Related Issues:

#25600

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Jun 8, 2020
@RyanCavanaugh
Copy link
Member

During an incremental rebuild, declaration files that aren't immediately included in the compilation process (i.e. those in node_modules, unless you specifically included them) aren't checked for up-to-dateness because figuring out which of those files are in the program in the first place is a major performance burden.

A few options:

  • Run -tsc -b -f to force a rebuild when you know these files have changed
  • Modify your include or files list to include node_modules/**/*.d.ts (warning: This will slow down all your incremental builds)

@brieb
Copy link
Author

brieb commented Jun 11, 2020

Got it. So sounds like ignoring the previous output directory (either by not restoring it or tsc -b -f) is the best we can do in this case. Wouldn't want to slow down all incremental builds.

What are the other output/cache invalidation conditions when we should use -f?

So far it sounds like:

  • When node_modules change

Anything else?

Would have maybe thought "When TypeScript version changes" but looks like the output tsbuildinfo files contain the version number.

@RyanCavanaugh
Copy link
Member

I think that's it, unless you have other places where .d.ts files might get read in from outside of node_modules (this is unlikely in my estimation, but it's possible).

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants