I am seeing ts-node-dev fail to hot reload files sometimes (even though it notices the file changes and tries to restart according to the output). I don't have any steps to repro and I'm seeing this randomly every 2-3 days.
It seems different enough from the other issues i've seen on here to make its own thread.
I will fully explain my workflow for the most recent case as it may shed some light.
the error looked like:
[INFO] 15:58:29 Restarting: /Users/ryan/app_engine/StoryDoodle/src/server/util/redis.ts has been modified
Using ts-node version 8.0.2, typescript version 3.3.3333
[ERROR] 15:58:32 ⨯ Unable to compile TypeScript:
src/server/cache/JSONCache.ts(5,34): error TS2551: Property 'getAsync' does not exist on type 'IPromisifedRedis'. Did you mean 'hmgetAsync'?
src/server/cache/JSONCache.ts(16,17): error TS2339: Property 'setAsync' does not exist on type 'IPromisifedRedis'.
This is a normal and explainable error but it was only possible with an old file of /util/redis.ts because that's the only time I had hmgetAsync type defined. In addition, other files which depend on this file are compiling correctly. (they should fail on that version of the file)
My flow:
my command: ts-node-dev --respawn src/server/index.ts
OS: MAC OSX 10.14
ts-node-dev version: 1.0.0-pre.32
I can do additional debugging the next time this happens. Just let me know what might help.
Edit from the future: this is almost assuredly incorrect but kept for reference.
After having other things failing concurrently, I suspect this may be OSX hitting the max number of files.
I suspect that ts-node-dev is silently catching/supressing the error somewhere. If you are seeing similar strange behaviour in OSX I would suggest running the following (stolen from elsewhere on the internet):
$ echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf
$ echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -w kern.maxfiles=65536
$ sudo sysctl -w kern.maxfilesperproc=65536
$ ulimit -n 65536
Maybe something like this possible, if you find a way to reproduce it consistently, please show it.
Also experiencing this issue. My reproduction steps are basically the same as the issue author.
Here's the simplified version:
This is extremely annoying to deal with and results in having to restart the compilation quite often, which can take close to a minute.
I think this issue is same as #60 . As I commented in https://github.com/whitecolor/ts-node-dev/issues/60#issuecomment-512212212, there is a non-intuitive (but NOT bug) behavior due to combination of TypeScript nature and incremental compilation.
I think it should considered as a bug since it prevents the app from starting without killing and restarting the whole process.
Yes, I totally agree which is why I stopped using ts-node-dev and opted for a combination of tsc-watch (for the first_success and success options it offers) and node-dev and it's been perfect. No issues whatsoever, but the config is not as straightforward. There are a few gotchas. Mainly, --noEmitOnErrors does not work with tsc's --watch option (which tsc-watch uses internally).
Or webpack :D
The compile error persists unless test.ts is modified to have different content. Just saving the file again will cause a recompile, but the error still persists.
I'll try to fix this with reinitializing compilation on compiler's error, not sure how it will affect large codebase, but this is the only way to get rid of this.
Maybe a potential solution would be to just recompile files with errors (after dumping the cache) instead of restarting the entire compilation?
Restarting the compilation will still likely result in this package being unusable.
I've been running into this too, except fairly frequently (on windows). It seems like every time I change a function signature or add a new file, I need to restart the process or it throws errors.
I've just started having similar issues constantly, where the Node server is restarted but uses old version of code, without any errors being present. Killing and restarting ts-node-dev takes the new code into use. This didn't happen earlier, I'm unsure what has changed. I think I upgraded Node in between.
I'm able to reproduce the problem with the following steps:
curl (not strictly necessary, reproduces without this step)console.log('HERE')curl --> 'HERE' does not get printedconsole.log('HERE2')curl --> 'HERE2' is printedI've tested this on 1.0.0-pre.50 (I'm unable to test on newer versions due to #208). Running on macOS. Raising the ulimit -n 30000 limit did not help, the suggested sysctl values are already >40000.
I've tried running with ts-node-dev --no-deps --watch 'src' --no-notify ./src/app.ts (which has worked previously) and ts-node-dev ./src/app.ts.
Any ideas?
@plaa make reproducible example repository.
@whitecolor I minimized the repo and finally figured out that if I remove the explicit --watch 'src' option, it starts reloading the files properly. This seems like a clear bug to me.
Example repo with reproduction instructions: https://github.com/plaa/ts-node-dev-watch-bug
@plaa why you are watching the required code that is already watched? This definitely may lead to some problems. --watch option is for watching arbitrary files/files, it is not intended to be used this way.
@whitecolor Configuration was like this when I joined the project. Possibly because there's some configuration / YAML files under src/ to be watched as well.
In any case, I wouldn't expect specifying files to be watched multiple times to cause such erratic behaviour. It should either cause a clear error, or (preferably) just ignore duplicates.
@plaa ok will see how to resolve it.
Most helpful comment
I've been running into this too, except fairly frequently (on windows). It seems like every time I change a function signature or add a new file, I need to restart the process or it throws errors.