Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ts-node-dev doesn't apply changes in auto reload

I have built an application using FeathersJS in Typescript but althought the nodemon for typescript (ts-node-dev) says that the server has restarted when a typescript file is changed, the change is not applyed. I always need to kill the application and start again to see the changes.

Here is the log:

[INFO] 15:43:51 Restarting: C:\api\src\models\favorites.model.ts has been modified
Using ts-node version 7.0.1, typescript version 3.9.3
info: Feathers application started on http://localhost:3030

Here is the dev script on package.json:

ts-node-dev --no-notify src/

Here is the tsconfig.json:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "outDir": "./lib",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true
  },
  "exclude": [
    "test"
  ]
}

And here is the package.json:

{
  "homepage": "",
  "private": true,
  "main": "src",
  "keywords": [
    "feathers"
  ],
  "contributors": [],
  "bugs": {},
  "directories": {
    "lib": "src",
    "test": "test/",
    "config": "config/"
  },
  "engines": {
    "node": "^12.0.0",
    "npm": ">= 3.0.0"
  },
  "scripts": {
    "test": "npm run compile && npm run mocha",
    "dev": "ts-node-dev --no-notify src/",
    "start": "npm run compile && node lib/",
    "mocha": "ts-mocha \"test/**/*.ts\" --recursive --exit",
    "compile": "shx rm -rf lib/ && tsc"
  },
  "prettier":{
    "singleQuote": true
  },
  "standard": {
    "env": [
      "mocha"
    ],
    "ignore": []
  },
  "types": "lib/",
  "dependencies": {
    "@feathersjs/authentication": "^4.5.3",
    "@feathersjs/authentication-local": "^4.5.4",
    "@feathersjs/authentication-oauth": "^4.5.4",
    "@feathersjs/configuration": "^4.5.3",
    "@feathersjs/errors": "^4.5.3",
    "@feathersjs/express": "^4.5.4",
    "@feathersjs/feathers": "^4.5.3",
    "@feathersjs/transport-commons": "^4.5.3",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "feathers-mongoose": "^8.3.0",
    "helmet": "^3.22.0",
    "mongodb-core": "^3.2.7",
    "mongoose": "^5.9.16",
    "serve-favicon": "^2.5.0",
    "winston": "^3.2.1"
  },
  "devDependencies": {
    "@types/compression": "^1.7.0",
    "@types/cors": "^2.8.6",
    "@types/helmet": "0.0.47",
    "@types/jsonwebtoken": "^8.5.0",
    "@types/mocha": "^7.0.2",
    "@types/mongoose": "^5.7.21",
    "@types/serve-favicon": "^2.5.0",
    "axios": "^0.19.2",
    "mocha": "^7.2.0",
    "nodemon": "^2.0.4",
    "shx": "^0.3.2",
    "ts-mocha": "^7.0.0",
    "ts-node-dev": "^1.0.0-pre.44",
    "tslint": "^6.1.2",
    "typescript": "^3.9.3"
  }
}
like image 350
Guilherme Zamberlam Pomini Avatar asked Mar 02 '23 09:03

Guilherme Zamberlam Pomini


2 Answers

Adding --exit-child to the npm dev script seemed to work for me.

"dev": "ts-node-dev --no-notify --exit-child src/",

https://stackoverflow.com/a/62447944/541281

like image 102
Shaun Avatar answered Mar 05 '23 16:03

Shaun


You need to tell the compiler to watch for changes. Add the following script or adjust your compile script with the watch flag:

"watch-ts": "tsc -w"

or

"compile": "shx rm -rf lib/ && tsc -w"

I took a closer look to your scripts and it seems to me that you should start your server from the compiled files (which I guess they are in the lib folder). If it's true your script for running the server should be for example:

"dev": "ts-node-dev --no-notify lib/server.js"

And you need to run in two separate terminal tabs:

npm run compile

and

npm run dev
like image 25
ionut-t Avatar answered Mar 05 '23 14:03

ionut-t