Typescript: tsc: watch mode doesn't discover new files

Created on 31 Aug 2015  ·  16Comments  ·  Source: microsoft/TypeScript

  • tsconfig with watch: true
  • start tsc
  • add a new file

Observe: it is not transpiled.

Bug Fixed

Most helpful comment

This is a very relevant issue to my organization. I would like you to re-open it.

We, and I assume many others, do our building in Docker containers, with source directories mounted in volumes. This gives us the assurance that all devs use the same environment as production. The Docker container, of course, is running Linux, where node's fs.watch is broken.

We let the tsc --watch process inside Docker pick up changes made on the outside, giving us a very nice dev cycle where compilation and tests are re-run automatically whenever a file is changed.

We absolutely want to keep using the native tsc --watch, since external modules have many issues:

  • Can never do as good a job with incremental recompilation as tsc can
  • Stop working if tsc changes
  • Maintainers stop maintaining them

So I ask you: Given the prevalence of people using Docker for development, please start considering Linux a supported platform, and ensure that your amazing --watch mode is fully supported there as well.

Since you don't want strict dependencies on external libraries, I suggest doing this with an optionalDependency.

All 16 comments

looks like another place where we should use the new node watch APIs: see #4643

+1 to have this soon. Is it for 1.7 like in #5076 or for 1.8 like here?

@alexeagle these two issues are both for 1.7

+1 to have this soon(er), this is annoying :)

@dbaeumer can you give latest a try?

Hmm - I'm using 2.0.10 and tsc -w does not spot new files. If I ctrl-c and restart, it then transpiles

@jmls Can you provide the following info:

  • your os
  • your node version
  • are you using a network mounted file system?
  • if possible, a small project that repros the issue.

Of course.

node: 4.6.1, 7.0.0 and 7.2.0
os: c9.io, running ubuntu 4.2.0-c9 #2 SMP x86_64 x86_64 x86_64 GNU/Linux

demo project at https://github.com/jmls/tsc-watch

I've created a new file by copying in the shell (cp part1.ts part2.ts) and creating a new file in the ide

Do you run tsc -w from project root path instead of from src? If so this is a known issue, as node's file watcher doesn't support recursive watching on linux.

I do - but I am amazed that tsc still uses fw.watch if it has such a fundamental problem.
Are you looking to fix this by using a package like chokidar ?

Indeed it is not ideal and creating a file watcher for node is out of the domain of our main focus. If there are no signs in addressing this in upcoming node updates, I do think a third-party package is the most likely approach. Though we are very cautious in adding third-party dependencies (currently we have none).

This is a very relevant issue to my organization. I would like you to re-open it.

We, and I assume many others, do our building in Docker containers, with source directories mounted in volumes. This gives us the assurance that all devs use the same environment as production. The Docker container, of course, is running Linux, where node's fs.watch is broken.

We let the tsc --watch process inside Docker pick up changes made on the outside, giving us a very nice dev cycle where compilation and tests are re-run automatically whenever a file is changed.

We absolutely want to keep using the native tsc --watch, since external modules have many issues:

  • Can never do as good a job with incremental recompilation as tsc can
  • Stop working if tsc changes
  • Maintainers stop maintaining them

So I ask you: Given the prevalence of people using Docker for development, please start considering Linux a supported platform, and ensure that your amazing --watch mode is fully supported there as well.

Since you don't want strict dependencies on external libraries, I suggest doing this with an optionalDependency.

const chokidar = require('chokidar');
const watcher = chokidar.watch(<dir>);

watcher.on('add', function(p){
 /// a file was added with path = p
});

this should be easy to add to tsc -w, right?

Alright so I already had created a tsc --watch wrapper that could spawn separate watchers for each tsconfig.json file in a project. tsc -w only seems to be able to watch for changes that pertain to one tsconfig.json file...

So I added this chokidar watch feature to the same project that can take into account multiple tsconfig.json files, so now the watcher will restart when a new file is added. I created this recently, so it's nothing great, but star it if you are interested in me making it better.

https://github.com/ORESoftware/tsc-multi-watch

screenshot 2017-06-19 22 20 06

Is this supposed to work? I don't see it with my system. Frustrating for bigger monorepos because have to restart a bunch of watchers for any file addition anywhere.

Ah figured it out, I had this in my tsconfig:

"include": ["/**/*"],

Changing to this works:

"include": ["**/*"],
Was this page helpful?
0 / 5 - 0 ratings

Related issues

fwanicka picture fwanicka  ·  3Comments

dlaberge picture dlaberge  ·  3Comments

Antony-Jones picture Antony-Jones  ·  3Comments

jbondc picture jbondc  ·  3Comments

manekinekko picture manekinekko  ·  3Comments