Typescript: Win10: tsc --watch not updating files when outDir present in tsconfig.json

Created on 17 Dec 2017  ·  12Comments  ·  Source: microsoft/TypeScript

TypeScript Version: 2.6.2
TypeScript Version: 2.7.0-dev.20171216
OS: windows 10

Works fine:

  • in MacOS
  • Version 2.5.3 in Windows

Code

Given...

{
"compilerOptions": {
    "module": "commonjs",
    "outDir": "dist"
},
"include": ["src/*.ts"]
}

and invoking

tsc -w

Expected behavior:
Changing any .ts file updates the .js files

Actual behavior:
Files are updated randomly. Sometimes they are updated, sometimes not

Bug Fixed Needs More Info

Most helpful comment

Works fine in 2.5.3. This seems to be an issue with the new --watch implementation which came in 2.6

All 12 comments

Works fine in 2.5.3. This seems to be an issue with the new --watch implementation which came in 2.6

@arnelism Can you please share the complete repro steps. I have verified that basic edits seem to work fine so it could be something more complex that results in this bug that i wont be able to investigate without more details. The files in your directory and which kind of edit is not resulting in output would be important in investigating this. Note that you can run tsc -w --listEmittedFiles to see list of files being written as part of compilation.
Also do you have noEmitOnError set to true ?

Could this be related to how the IDE saves files? Using WebStorm on Windows 7 with TypeScript 2.6.2, change detection seems to work flawlessly when disabling _'Use "safe write" (save changes to a temporary file first)'_. I think it is enabled by default, but I am not sure.

image

  • With the "safe write" option enabled, when change detection randomly fails, tsc --watch --extendedDiagnostics --listEmittedFiles ... shows:

    ...
    FileWatcher:: Close: PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts
    ...
    Synchronizing program
    FileWatcher:: Added: PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts
    

    Somehow, this "new" file is then not actually re-transpiled into JavaScript?

  • With the same settings, when change detection happens to be okay for a minor edit in the very same file, I'd get:

    ...
    FileWatcher:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts 1 PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts
    ...
    Synchronizing program
    TSFILE: D:/home/workspaces/ipp-branch/server/dist/api/base-audit.service.js.map
    TSFILE: D:/home/workspaces/ipp-branch/server/dist/api/base-audit.service.js
    
  • With the "safe write" option enabled, --extendedDiagnostics shows a lot of files that the compiler cannot handle; see the full output at the end of my comment below. When disabling the "safe write" option, the output is much cleaner:

    FileWatcher:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts 1 PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts
    FileWatcher:: Elapsed: 1ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts 1 PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts
    12:41:45 - File change detected. Starting incremental compilation...
    
    Synchronizing program
    TSFILE: D:/home/workspaces/ipp-branch/server/dist/api/base-audit.service.js.map
    TSFILE: D:/home/workspaces/ipp-branch/server/dist/api/base-audit.service.js
    

    Above, I've not removed any output; this is all that is logged when changes are detected with "safe write" disabled along with --extendedDiagnostics --listEmittedFiles.

Below are the results when the "safe write" option is enabled.

"safe write" enabled, change detection randomly fails

DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 8ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server
Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___
DirectoryWatcher recursive:: Elapsed: 1ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 1ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 0ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server
FileWatcher:: Close: PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts
DirectoryWatcher recursive:: Elapsed: 1ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server
Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___
DirectoryWatcher recursive:: Elapsed: 0ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 0ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 1ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server

Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___

DirectoryWatcher recursive:: Elapsed: 21ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 1ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 1ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server

Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___
DirectoryWatcher recursive:: Elapsed: 1ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server
11:43:52 - File change detected. Starting incremental compilation...


Synchronizing program
FileWatcher:: Added: PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts

"safe write" enabled, change detection randomly okay

DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 4ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server
Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___
DirectoryWatcher recursive:: Elapsed: 0ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server

DirectoryWatcher recursive:: Elapsed: 1ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Elapsed: 1ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Elapsed: 4ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server
Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___
DirectoryWatcher recursive:: Elapsed: 1ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Elapsed: 0ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Elapsed: 0ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server
Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___
DirectoryWatcher recursive:: Elapsed: 1ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_tmp___ PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Elapsed: 1ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts PathInfo: d:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Elapsed: 0ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: D:/home/workspaces/ipp-branch/server
DirectoryWatcher recursive:: Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server
Project: D:/home/workspaces/ipp-branch/server/tsconfig.json Detected file add/remove of non supported extension: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___
DirectoryWatcher recursive:: Elapsed: 0ms Trigger: d:/home/workspaces/ipp-branch/server/api/base-audit.service.ts___jb_old___ PathInfo: d:/home/workspaces/ipp-branch/server
FileWatcher:: Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts 1 PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts

FileWatcher:: Elapsed: 0ms Trigger: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts 1 PathInfo: D:/home/workspaces/ipp-branch/server/api/base-audit.service.ts

11:45:29 - File change detected. Starting incremental compilation...


Synchronizing program

TSFILE: D:/home/workspaces/ipp-branch/server/dist/api/base-audit.service.js.map
TSFILE: D:/home/workspaces/ipp-branch/server/dist/api/base-audit.service.js

Looks like same cause as #21444 and should be fixed by #21693, If possible give the drop out of #21693 try and see if that fixes the issue for you. Thanks

Yes this issue look like #21444. As you could see simply with the changes in the title of #21444, I've tried to track why and when a file is updated, but it was very strange especially with files in "src/*.ts": maybe we can say only that « Files are updated randomly. » as said @arnelism ;-).

In #21444, I've already said that maybe this issue look like the present issue.

@avbentem, I'm also interested to know if it resolves the problem !

@JulioJu This issue will mostly come up specially when the directory watch is invoked for the wild card directory from tsconfig.json with file deletion. (and later creation)

If possible give the drop out of #21693 try and see if that fixes the issue for you

@sheetalkamat would that simply be a npm install -g typescript@next? Then I could try at work next week.

If not: one might also need to test WebStorm's _"safe write"_ while editing multiple large files and saving them in one go (like maybe along with WebStorm's _"Save files on frame deactivation"_). This might then take some more time to get the final TypeScript files on disk, I guess.

image

yes please try typescript@next

Sorry for the delay; I had trouble testing in an Angular CLI project, but now tested with Express.js instead. On a (slow) Windows 7 with quite a few virus scanners running:

  • All fine with the last nightly and WebStorm's "safe write" option enabled.

So: solved for me :-)


All of the following just for your information, unrelated to this very issue, and not a problem for me but please let me know if you think it matters and should be reported as some problem with @next:

In an Angular CLI project, after running npm i --save-dev typescript@next (getting me "typescript": "^2.8.0-dev.20180215" today), and after even removing node_modules and pacage-lock.json, _and_ running npm cache verify: executing npm i _does_ get me a new node_modules/typescript folder (in which package.json nicely shows "_id": "[email protected]"). However, it's not listed in npm list typescript. Instead, that output shows me an older version for the dependencies of @angular/cli but no TypeScript at all at the root level:

`-- @angular/[email protected]
  +-- @angular-devkit/[email protected]
  | `-- [email protected]
  `-- @schematics/[email protected]
    `-- [email protected]

This makes Angular CLI throw Could not find local "typescript" package. The "@ngtools/webpack" package requires a local "typescript@^2.0.2" package to be installed.

Using npm i --save-dev [email protected] does get me TypeScript at the root level, in the last line below:

+-- @angular/[email protected]
| +-- @angular-devkit/[email protected]
| | `-- [email protected]
| `-- @schematics/[email protected]
|   `-- [email protected]
`-- [email protected]

NPM 5.6.0.

Thanks! I ran into this to switching from a multi TS project to a single TS file (using the same tsconfig), and installing @next worked for me too (it would detect file changes, but not actually transpile)!

Closing this since it is fixed now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kyasbal-1994 picture kyasbal-1994  ·  3Comments

Antony-Jones picture Antony-Jones  ·  3Comments

jbondc picture jbondc  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

remojansen picture remojansen  ·  3Comments