Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ts-node-dev not restarting when changes made

Here are my files :

package.json :

"scripts": {
  "generate-interfaces": "ts-node src/cli/generate-interfaces.ts",
  "dist": "npm run generate-interfaces && rm -rf dist && tsc && cp -r static/ dist/ && cp -r resource/ dist/",
  "prestart": "npm run generate-interfaces",
  "start": "ts-node-dev --respawn --transpileOnly --no-notify ./src/index.ts",
  "start:inspect": "ts-node-dev --no-deps --inspect -- ./src/index.ts",
  "pretest": "npm run generate-interfaces",
  "test": "jest"
 }

tsconfig.json

{
"compilerOptions": {
"declaration": true,
"target": "es2017",
"module": "commonjs",
"esModuleInterop": true,
"outDir": "dist",
"sourceMap": true,
"skipLibCheck": true,
"typeRoots": ["node_modules/@types", "./typings", "node_modules/**/*.d.ts"],
"lib": ["esnext"]
},
"include": ["src/**/*.ts", "./typings/**/*.d.ts"],
"exclude": ["node_modules/**", "dist"]
}

When I do any changes, I get the little popup, but it doesn't actually restart the server not sure what I am doing wrong here.

Note: The first time I do changes after server restart manually it shows me a popup and something like this in the terminal [INFO] 22:07:09 Restarting: src/analytics-engine.ts has been modified after that no changes detection.

like image 552
Himanshu Teotia Avatar asked Jun 17 '20 16:06

Himanshu Teotia


People also ask

What is the difference between ts-node and ts-node-Dev?

According to the StackShare community, ts-node has a broader approval, being mentioned in 538 company stacks & 274 developers stacks; compared to ts-node-dev, which is listed in 24 company stacks and 7 developer stacks.

Is it OK to use ts-node in production?

No you shouldn't use it in production, even though it will cache the compiled files it'll be slower to start and consume more memory because it keeps around an instance of the compiler and files in memory.

How do I restart node JS?

In this case, if we make any changes to the project then we will have to restart the server by killing it using CTRL+C and then typing the same command again.

Does Nodemon use ts-node?

As of v1. 19.0, nodemon has inbuilt support for TypeScript files with help from ts-node that requires no manual configuration. By default, nodemon uses the node CLI as an execution program for running JavaScript files; for TypeScript files, nodemon uses ts-node as the execution program instead.


2 Answers

The issue is resolved now. I found out the problem using --debug that it was an error related to 'SIGTERM'. So I added a flag --exit-child in my npm start script.

like image 101
Himanshu Teotia Avatar answered Oct 01 '22 15:10

Himanshu Teotia


--exit-child worked for me too.

Example in package.json

"scripts": {
        "start": "ts-node-dev --respawn --transpile-only --exit-child --watch src src/index.ts"
    },
like image 26
Michael Brenndoerfer Avatar answered Oct 01 '22 15:10

Michael Brenndoerfer