ts-node-dev: TypeScript Slow Restarting Time
When I start app ts compile very fast, but when I change some file It take to long to restart, in which may be problem ?
./node_modules/.bin/tsc -project ./tsconfig.json --diagnostics
Files: 403
Lines: 64126
Nodes: 237079
Identifiers: 83972
Symbols: 67964
Types: 7966
Memory used: 112027K
I/O read: 0.04s
I/O write: 0.09s
Parse time: 0.89s
Bind time: 0.28s
Check time: 0.66s
Emit time: 0.45s
Total time: 2.28s
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["es6", "es2017"],
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"exclude": ["node_modules"],
"include": ["src"]
}
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 27
- Comments: 38 (7 by maintainers)
Commits related to this issue
- fix(graphql): ignore node_modules to reduce rebuild time Add `--ignore-watch node_modules` to reduce rebuild time https://github.com/whitecolor/ts-node-dev/issues/51 — committed to opendevtools/supreme-ts by believer 5 years ago
- Use --no-deps in ts-node-dev Right now ts-node-dev watches all direct dependencies in node_modules which is unnecessary. [Adding --no-deps](https://github.com/whitecolor/ts-node-dev/issues/51#issueco... — committed to inian/actionhero by inian 5 years ago
- Use --no-deps in ts-node-dev Right now ts-node-dev watches all direct dependencies in node_modules which is unnecessary. [Adding --no-deps](https://github.com/whitecolor/ts-node-dev/issues/51#issueco... — committed to actionhero/actionhero by inian 5 years ago
I have the same problem and just did some debugging as @whitecolor advised.
This is what I found
This line: https://github.com/whitecolor/ts-node-dev/blob/master/lib/index.js#L55 (
watcher.removeAll()
) takes 31 seconds to execute. Upon further investigation, it turns out thatwatcher.list()
contains a whopping 1323 elements, which includes mainly the files innode_modules
.Solution
Include the
--ignore-watch node_modules
flag in your dev script. Mine now looks like this:watcher.list()
now only contains my 27 source files, and restarting my app is done in about 1 second again.My solution with nodemon:
Install nodemon
npm i nodemon -D
Create
nodemon.json
configStart script
"start": "ts-node -r tsconfig-paths/register src/index.ts",
I have the same problem and the solution that worked for me is to use
--exit-child
Another solution is graceful shutdown The problem is that ts-node cannot kill a child process for some reason.I ended up here
ts-node-dev --poll --respawn --transpile-only --no-deps --exit-child ./src/index.ts
thanks to https://github.com/wclr/ts-node-dev/issues/69#issuecomment-493675960
I’ve been facing this issue as well. A normal stop + start of the server using
ts-node
takes a second, while when I usets-node-dev
, it detects a file change instantly, but post that it takes about 5 seconds to issue a server restart.I’m using
ts-node-dev
like so -I got same problem and
--ignore-watch node_modules
resolved it too.And I found
--no-deps
also works as node-dev README saysa little simpler …?
--no-deps
or--ignore-watch node_modules
should definitely be enabled by defaultso start up is very quick, but when restarting after saving a file i get…
it stays on this for about 45 seconds, as you can see from the time.
Then this runs.
Passing the
--poll
argument tots-node-dev
fixed the hang onRemoving all watchers from files
for me without ignoring anything (on OSX).// tsconfig.json
--transpileOnly
is deprecated. Use--transpile-only
insteadI had the same problem where
Removing all watchers from files
hung for a very long time on restarts, I gave up waiting. (If relevant: on MacOS and Activity Monitor showedfseventsd
using a lot of CPU.)Adding this argument
--ignore-watch node_modules
was the solution for me also.From reading the
README.md
I thought this was the default, but maybe I misunderstood?@intellix I’m not sure this would help you, but take a look at this lib: https://www.npmjs.com/package/patch-package
I’m thinking you could use
--ignore-watch node_modules
and still reload the server by using this lib. Besides, it’s a nice lib if you didn’t know it yet 😃doesn’t restart at all for me, I think it’s related change is detected, because I see
[INFO] 23:39:05 Restarting: /Users/shook/Development/sHooKDT-task-2018/src/index.ts has been modified
in terminal, but nothing happens even after 15 minutes