You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"tsc -w" will compile and watch, then how to run tsc in "watch-only" mode without compiling? #12996
Hi, I'm finding it confusing when using "tsc -w". From angular quickstart guide and almost every tutorial, I see similar things in package.json as the line below:
Expected behavior:
The command should compile only once, and then "watch" and "start lite-server" at the same time.
Actual behavior:
The command compiles once first. Then "compile and watch" and "start lite-server" at the same time. The actual result is it compiled twice.
I'm finding this annoying especially when running with karma (which watches for JS file changes).
From the above code, when karma start karma.conf.js runs, tests start running. At the same time (due to concurrently), "tsc -w" starts running and fires another round of TS compilation, which changed the output JS files. Then Karma detected these JS file changes, stopped the currently running (partially or finished) tests, and started re-run the tests again.
From my understanding, what we wanted from "tsc && concurrently 'tsc -w' 'do-something' " is compile && (watch and do-something concurrently). But we actually got "compile && (compile-then-watch and do-something concurrently. Do we have any options to make "tsc -w" only watch, but don't compile?
Reacted by Daphne Maddox, Arjan, Amir Arad, Christophe Le Besnerais, Quinn Turner, Tom Clift, Vasiliy Yorkin, Dmitry Zakharov, Dmitri, Jeremy Danyow and 44 more
I suppose we could add this, but it'd need to be well-hidden enough that people wouldn't accidently use it and think TS was broken for not compiling the first time around.
I'm assuming they wrote their script that way so that lite-server didn't launch and not see the .js file and panic. It seems like the "right" fix here is to only invoke the first tsc conditionally on the target output file not existing. Adding more switches to tsc to support a scenario like this is perhaps fixing the problem in the wrong place.
currentlly tsc will update the file if it has changed since the last time it wrote it. we can make it so that it reads the output file the first time if it exists.
I think the fact that "tsc && concurrently \"tsc -w\" \"lite-server\" " actually compiles the same code twice is already inefficient due to how tsc -w behaves (compile and watch).
All I'm looking for is something like tsc -w --no-initial-compille.
Reacted by Emmanuel Buah, Stepan Repin, Philipp Katz, djimoh5, Andy Coenen, Daphne Maddox, Aymeric Beaumet, Arjan, Amir Arad, Michael and 58 more
Reacted by Glogo, Eric Ferreira, Luky Wong, Patrick Michalina, Vituchon and 流浪大法师
I run into this as well. It's useful to be able to compile or watch or compile + watch. tsc -w --no-initial-compile should solve the issue or breakout -w to only setup watch (no compilation) and only compile on future changes.
Reacted by Jeremy Danyow, Spencer Kaiser, Heartlander, Andrés Fuentes, Eric Ferreira, Michal, 流浪大法师 and pedange
start another process when the initial transpilation is done and watch mode begins.
not touch the target files more than once during that process (unless the source actually changed)
I'm affected by this usually when chaining watchers for dev-mode over a complex multy-project workspace. for instance several typescript watchers that produce dependencies for each other, and a webpack-dev-server that bundles all their target files whenever any of them change.
Reacted by Eric Nolte, Ján Dzurek, Michal, Luis Pais, Gavin Golden, Jacob Raihle and Angelo Gazzola
TL;DR: This is exactly the same problem Yao Lu (@yaooluu) described above
It'll be great to have this, could be useful for monorepos (e.g. managed by lerna), where you have multiple packages that you want to test (I mean cross-package / integration testing).
In my case to accomplish this and do TDD I have to watch and rebuild (tsc -w) my packages constantly, at the same time I run jest in a watch-mode. The problem is that when I ran these two tasks in parallel jest is usually starts faster so I have to run just tsc to build dependency sub-packages first, and only then I can run tsc -w and jest in parallel. Thats why I have to run tsc two times.
Just as an aside, I'm using https://github.com/gilamran/tsc-watch which extends the built-in compiler with an --onSuccess option, which can then be used like:
(Another aside: it seems the above does not work with projects in subfolders, such as "tsc-watch --project ./server --outDir ./server/dist --onSuccess \"nodemon ./server/dist/bin/www.js\"", for which the first compilation is fine, but compilation results of changes do somehow not end up in ./server/dist.)
Reacted by Johnny, Rizky Luthfianto, Puria Kordrostami, Oliver Boudet, Junho Yeo, polv, Julian Alimin, Towerss, Michael J. Fordham, Henderson Fernandes and 2 more
I think --incremental actually addresses this to a high enough degree - with that flag turned on, the next watch invocation after a full build will be effectively free. Please do comment (with specifics) if you disagree and we can re-evaluate
Reacted by Dan Dombrowski, mxhx, Jiabin Peng, felixhayashi, Dmitri Pavlutin, Paul Biccherai, 流浪大法师, Denta and David Borges
with this setup, i have a tsc watching for any files changes in src and rebuilding them into build, simultaneously i have nodemon restarting the node server whenever the build folder changes.
On start, I have to perform a fresh build and copy since tsc watch does not allow for post-compile scripts to run (such as copying over non-ts files), and then I have tsc:watch setup to rebuild, and thus restart the server anytime ts files change.
What tends to happen here is that my server will startup right away, but then since build:watch always performs a rebuild, this causes my server to autoreload everytime I start it up. This is quite annoying since the app will work, and then suddenly a network error is thrown after the ~3 second tsc rebuild. Since the server startup takes about 3-5 seconds, this makes the server start time go from 3 seconds to about 10-15 seconds everytime the docker image is booted.
This was so annoying that I had to start my server with two commands and i just run build:watch outside of the docker container. it;s quite easy to forget to run both commands and really tricky bugs have come out of just not having the build:watch command running in another window.
This workflow could be fixed by either allowing:
a command to be run every time tsc rebuilds
allowing watch-only mode so there is optionally no initial re-compilation
Reacted by Jeremy Danyow, Muhammad and Wade Peterson
watch-only mode so there is optionally no initial re-compilation
Try --incremental, it does exactly that, i.e it won't rebuild the same stuff all over again. You should use task automation if you need to copy files or do any other kind of pre-processing, expecting tsc to do this makes no sense.
a command to be run every time tsc rebuilds
Some way of knowing when tsc rebuilds files is a good idea. I use tsc-watch for that, but it parses the CLI output which is not optimal.
Reacted by Ryan Cavanaugh, Mikael Lirbank, Cédric Marcone, Ryutaro Yamada and Gabriel Rocha de Oliveira
Activity
RyanCavanaugh commentedon Dec 21, 2016
I suppose we could add this, but it'd need to be well-hidden enough that people wouldn't accidently use it and think TS was broken for not compiling the first time around.
I'm assuming they wrote their script that way so that
lite-serverdidn't launch and not see the .js file and panic. It seems like the "right" fix here is to only invoke the firsttscconditionally on the target output file not existing. Adding more switches to tsc to support a scenario like this is perhaps fixing the problem in the wrong place.mhegazy commentedon Dec 21, 2016
currentlly tsc will update the file if it has changed since the last time it wrote it. we can make it so that it reads the output file the first time if it exists.
yaooluu commentedon Dec 24, 2016
I think the fact that
"tsc && concurrently \"tsc -w\" \"lite-server\" "actually compiles the same code twice is already inefficient due to howtsc -wbehaves (compile and watch).All I'm looking for is something like
tsc -w --no-initial-compille.emmanuelbuah commentedon Apr 17, 2017
I run into this as well. It's useful to be able to compile or watch or compile + watch.
tsc -w --no-initial-compileshould solve the issue or breakout -w to only setup watch (no compilation) and only compile on future changes.pushfactory commentedon Jul 16, 2017
Couldn't we just remove the first 'tsc' from that line of code?
"start": "concurrently \"tsc -w\" \"lite-server\" "avbentem commentedon Jul 17, 2017
But then, mhvj, it might still be compiling when the server is already started?
amir-arad commentedon Jul 22, 2017
IMO the essential features here are:
I'm affected by this usually when chaining watchers for dev-mode over a complex multy-project workspace. for instance several typescript watchers that produce dependencies for each other, and a webpack-dev-server that bundles all their target files whenever any of them change.
vyorkin commentedon Sep 17, 2017
TL;DR: This is exactly the same problem Yao Lu (@yaooluu) described above
It'll be great to have this, could be useful for monorepos (e.g. managed by lerna), where you have multiple packages that you want to test (I mean cross-package / integration testing).
In my case to accomplish this and do TDD I have to watch and rebuild (
tsc -w) my packages constantly, at the same time I runjestin a watch-mode. The problem is that when I ran these two tasks in paralleljestis usually starts faster so I have to run justtscto build dependency sub-packages first, and only then I can runtsc -wandjestin parallel. Thats why I have to runtsctwo times.vyorkin commentedon Sep 18, 2017
if understand correctly, to start working on this and have a chance that my PR will be accepted this feature needs to
according to CONTRIBUTING
what should be done to make it approved? does it need just more feedback or I can start working on it, submit a PR and only then it could be approved?
RyanCavanaugh commentedon Sep 19, 2017
Mohamed Hegazy (@mhegazy) thoughts on taking a PR for a flag to skip the initial watch cycle?
itsUndefined commentedon Nov 17, 2017
This needs to be done.
mhegazy commentedon Nov 17, 2017
Sure, we would consider a PR for it.
avbentem commentedon Dec 5, 2017
Just as an aside, I'm using https://github.com/gilamran/tsc-watch which extends the built-in compiler with an
--onSuccessoption, which can then be used like:(Another aside: it seems the above does not work with projects in subfolders, such as
"tsc-watch --project ./server --outDir ./server/dist --onSuccess \"nodemon ./server/dist/bin/www.js\"", for which the first compilation is fine, but compilation results of changes do somehow not end up in./server/dist.)17 remaining items
ericbf commentedon Mar 22, 2019
Any update here?
dziegelbein commentedon Apr 26, 2019
I created a package called runmon to work around this very issue.
sheetalkamat commentedon Apr 26, 2019
--incrementalshould allow you to build incrementally all the time.pronebird commentedon Apr 26, 2019
Sheetal Nandi (@sheetalkamat) can you elaborate how that enables us to use
tsc -wdirectly without usingtsc-watch?sheetalkamat commentedon Apr 30, 2019
Andrej Mihajlov (@pronebird) You can read more about --incremental at https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#faster-subsequent-builds-with-the---incremental-flag
kirill-konshin commentedon May 4, 2019
Sheetal Nandi (@sheetalkamat) perfecto, seems to be working!
tsc && tsc -wruns much faster.pronebird commentedon May 4, 2019
Sheetal Nandi (@sheetalkamat) now I got it. Thank you!
lukywong commentedon May 31, 2019
+1 any update on this?
RyanCavanaugh commentedon Aug 19, 2019
I think
--incrementalactually addresses this to a high enough degree - with that flag turned on, the nextwatchinvocation after a full build will be effectively free. Please do comment (with specifics) if you disagree and we can re-evaluatemichaelfarrell76 commentedon Aug 23, 2019
I disagree with the above statement. here is the workflow I have setup:
I am running a node server inside of a docker container with the folder structure
I want to run a single start command inside of the docker container, i.e.
with the following package.json scripts:
with this setup, i have a tsc watching for any files changes in
srcand rebuilding them intobuild, simultaneously i have nodemon restarting the node server whenever thebuildfolder changes.On start, I have to perform a fresh build and copy since tsc watch does not allow for post-compile scripts to run (such as copying over non-ts files), and then I have tsc:watch setup to rebuild, and thus restart the server anytime ts files change.
What tends to happen here is that my server will startup right away, but then since build:watch always performs a rebuild, this causes my server to autoreload everytime I start it up. This is quite annoying since the app will work, and then suddenly a network error is thrown after the ~3 second tsc rebuild. Since the server startup takes about 3-5 seconds, this makes the server start time go from 3 seconds to about 10-15 seconds everytime the docker image is booted.
This was so annoying that I had to start my server with two commands and i just run build:watch outside of the docker container. it;s quite easy to forget to run both commands and really tricky bugs have come out of just not having the build:watch command running in another window.
This workflow could be fixed by either allowing:
pronebird commentedon Aug 23, 2019
Michael Farrell (@michaelfarrell76)
Try
--incremental, it does exactly that, i.e it won't rebuild the same stuff all over again. You should use task automation if you need to copy files or do any other kind of pre-processing, expectingtscto do this makes no sense.Some way of knowing when
tscrebuilds files is a good idea. I usetsc-watchfor that, but it parses the CLI output which is not optimal.[Dev] Enable TypeScript's --incremental flag for faster subsequent bu…
[Dev] Enable TypeScript's --incremental flag for faster subsequent bu…