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: watch mode doesn't discover new files #4553

Closed
dbaeumer opened this issue Aug 31, 2015 · 16 comments
Closed

tsc: watch mode doesn't discover new files #4553

dbaeumer opened this issue Aug 31, 2015 · 16 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@dbaeumer
Copy link
Member

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

Observe: it is not transpiled.

@mhegazy mhegazy added the Bug A bug in TypeScript label Aug 31, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Sep 18, 2015

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

@alexeagle
Copy link
Contributor

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

@zhengbli
Copy link
Contributor

zhengbli commented Oct 5, 2015

@alexeagle these two issues are both for 1.7

@dsebastien
Copy link

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

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Oct 15, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Oct 15, 2015

@dbaeumer can you give latest a try?

@jmls
Copy link

jmls commented Dec 16, 2016

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

@zhengbli
Copy link
Contributor

@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.

@jmls
Copy link

jmls commented Dec 21, 2016

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

@zhengbli
Copy link
Contributor

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.

@jmls
Copy link

jmls commented Dec 21, 2016

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 ?

@zhengbli
Copy link
Contributor

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).

@OliverUv
Copy link

OliverUv commented Apr 8, 2017

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.

@ORESoftware
Copy link

ORESoftware commented Jun 20, 2017

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?

@ORESoftware
Copy link

ORESoftware commented Jun 20, 2017

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

@natew
Copy link

natew commented May 26, 2018

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.

@natew
Copy link

natew commented May 26, 2018

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

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

Changing to this works:

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

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

9 participants