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

tsc --build --watch emitting unchanged files to disk #47309

Closed
frags51 opened this issue Jan 4, 2022 · 5 comments
Closed

tsc --build --watch emitting unchanged files to disk #47309

frags51 opened this issue Jan 4, 2022 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@frags51
Copy link

frags51 commented Jan 4, 2022

Bug Report

Similar to #29927

🔎 Search Terms

tsc --watch writing to disk too often

🕗 Version & Regression Information

Occurring in TS 3.9.5 (and also tried on TS 4.5, although we did get TS2571 errors in our code while using TS4.5.
We are using TS in a React-Native project. This issue is causing longer times to hot reload in RN.

tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "jsx": "react",
    "moduleResolution": "node",
    "importHelpers": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "sourceMap": false,
    "strictNullChecks": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "forceConsistentCasingInFileNames": true,
    "noImplicitAny": true,
    "preserveConstEnums": true,
    "noErrorTruncation": true,
    "strict": true,
    "declaration": true,
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true
  },
  "compileOnSave": true
}

🙁 Actual behavior

On changing a single TS file, multiple JS files are written to disk. Can confirm that they need to be actually changed.

🙂 Expected behavior

Only the single (or files that actually need to be changed) should be written to disk.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jan 4, 2022
@RyanCavanaugh
Copy link
Member

This is not necessarily unexpected behavior for --build mode since it is a timestamp-based incremental build system. The content and structure of the files matters here and we'd need a complete repro to determine if there's a bug or not.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jan 7, 2022

For what it's worth, I've proposed a possible mitigation in #46677. But it's hard to say without a full repro.

@frags51
Copy link
Author

frags51 commented Jan 7, 2022

Project structure is as follows:
We have used Lerna to create a monorepo for our React Native app.

packages
 | - A (Root package, depends on B, C. react-native start is run from this package)
   | src/.ts(x) (Files from B, C are imported as import Something from 'B/build/Something' and not 'B/Something'
   | app.js, index.js, tsconfig (at root level)
   | resources/images
   | build/
.js (Emitted by tsc)
 | - B
   | src/.ts
   | tsconfig (at root level)
   | build/
.js (Emitted by tsc)
 | - C
   | src/.ts
   | tsconfig (at root level)
   | build/
.js (Emitted by tsc)

tsc --build is needed so that changes in B, C also lead to a hot reload. If we remove --build still we see multiple JS files being emitted on change to TS file in A. (Although these two situations may be occurring due to different causes)

@frags51
Copy link
Author

frags51 commented Jan 10, 2022

We got our scenario working by not using tsc at all (just using tsc --noEmit for compilation errors) and instead letting Metro/Babel transform ts files to js during dev. We also had to move to consuming TS files directly (earlier we were sending JS files to metro)

@DanielRosenwasser
Copy link
Member

Sorry that you had to find mitigations for this. I believe that this is fixed now (since #46677 is fixed). If you still run into this in other projects, you can now try a nightly version of TypeScript and see if things are improved at all.

@DanielRosenwasser DanielRosenwasser added Duplicate An existing issue was already created and removed Needs More Info The issue still hasn't been fully clarified labels Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants