ts-node is sporadically staying alive on changes. It happens with nodemon and VSCode debug

Created on 24 Mar 2020  Â·  6Comments  Â·  Source: TypeStrong/ts-node

Expected Behavior

The ts-node process to be killed.

Actual Behavior

[start] 🚀 server listening on 0.0.0.0:3000, in development
[start] ⌛ Server started in 1s
[start] [nodemon] restarting due to changes...
[start] [nodemon] starting `ts-node --files src/server.ts`
[start] Error: listen EADDRINUSE: address already in use 0.0.0.0:3000
[start]     at Server.setupListenHandle [as _listen2] (net.js:1309:16)
[start]     at listenInCluster (net.js:1357:12)
[start]     at doListen (net.js:1496:7)
[start]     at processTicksAndRejections (internal/process/task_queues.js:85:21)
[start] [nodemon] app crashed - waiting for file changes before starting...

Steps to reproduce the problem

I apologize about the lack of detail and steps to reproduce at the moment. I'll spin up a new environment and see if I can't get it to behave in the same fashion.

I changed my package file to include latest on all dependencies hoping that may help. It did not.


Minimal reproduction

The issue is intermittent so I don't know how to reproduce it at the moment. I'm hoping there's something silly that I did or missed that could solve the issue. I'll update with as much info as I can. If I'm able to pin point exactly what's causing it to hang, I'll update this.

I will most definitely create a reproduction repo. The code is fairly lightweight at the moment, mostly just koa + mongoose for a thin API. The problem started showing up recently. I have no idea what triggered it yet.

Specifications

  • ts-node version: 8.8.1
  • TypeScript version: 3.8.3
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es6",
    "strict": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist"
  },
  "include": ["src/**/*"]
}
  • node version: 13.8.0
  • Operating system and version: macOS Catalina
  • If Windows, are you using WSL or WSL2?:
needs more info

Most helpful comment

@chanced This issue is TOTALLY related to ts-node.
It happens even if you run ts-node directly.

All 6 comments

What command are you running to start nodemon? npm run, yarn, are you typing something at your bash shell? Which lines in the log you posted are coming from your app, and which are coming from nodemon? I don't want to assume.

I'm unfamiliar with nodemon. If I understand correctly, nodemon is launching a process, then trying to kill it? This sounds like a nodemon failure, where nodemon is calling process.kill() and somehow not waiting for the process to die.

Have you looked at this thread? Seems like this might be a common nodemon issue with a bunch of solutions: https://github.com/remy/nodemon/issues/1316

I have another suggestion that I can share once you've confirmed answers to the above questions.

@cspotcode Woops, I meant to post my commands, sorry!

nodemon --watch src --ext ts --exec 'ts-node --files src/server.ts'

The thing is it happens with VS Code debug too using the launch.json in the readme:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "ts-node",
      "type": "node",
      "request": "launch",
      "args": ["${workspaceFolder}/src/server.ts"],
      "runtimeArgs": ["-r", "ts-node/register"],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "internalConsoleOptions": "openOnSessionStart"
    }
  ]
}

@chanced You mention that it stays alive "on changes." What does VSCode do in that situation? I don't see anything in your VSCode config that restarts on changes.

Did you confirm that this does not happen when you do not use ts-node?

I'll update this if I can ever get it to reproduce on this demo app. So far it's working smoothly.

I'll close this issue for now as it may be unrelated to ts-node.

@chanced This issue is TOTALLY related to ts-node.
It happens even if you run ts-node directly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

max-block picture max-block  Â·  4Comments

aj-r picture aj-r  Â·  3Comments

sanex3339 picture sanex3339  Â·  4Comments

JoseLion picture JoseLion  Â·  3Comments

watzon picture watzon  Â·  3Comments