wclr / ts-node-dev

Compiles your TS app and restarts when files are modified.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Watch behaves irregular

bjornandersson opened this issue · comments

Issue description

Step 1

Run the repro code with npm run dev:a ("ts-node-dev --respawn src/index.ts")
Save the file tmp/mymodule.js.

Ts-node-dev triggers a reload because the file is required which is kind of not expected.

Step 2

Run the repro code with npm run dev:b ("ts-node-dev --respawn --ignore-watch ['tmp'] src/index.ts")
Save the file tmp/mymodule.js.

Ts-node-dev does not trigger a reload, which is expected.

Save the file src/index.ts.

Ts-node-dev does not trigger a reload, which is not expected.

Context

Ubuntu 20.04, ts-node-dev: "version": "1.1.8",

Repro code:
https://github.com/bjornandersson/ts-node-dev-test

I was able to reproduce this as well and went down a rabbit hole of different ways to run TypeScript + Node with automatic reloading.

I found one option that's just as fast as ts-node-dev and may be more reliable: using nodemon (or node-dev) plus ts-node's experimental swc integration: https://github.com/TypeStrong/ts-node#bundled-swc-integration

I also found an option that relies just on nodemon plus the TypeScript compiler using the latter's incremental transpilation feature. It's not as fast as ts-node + swc or even as fast as ts-node-dev, but it's a nice tradeoff for greater simplicity but still decent speeds, e.g.

"dev": "nodemon -e ts --watch src .env --exec \"tsc --incremental && node dist/index.js\"",

More here: https://stackoverflow.com/a/70933036/399105

Under WSL2 I used the env variable CHOKIDAR_USEPOLLING=true ie

CHOKIDAR_USEPOLLING=true ts-node-dev --exit-child --respawn --transpile-only --ignore-watch node_modules src/app.ts