3

I tried using both nodemon + ts-node as well as ts-node-dev to have auto-reload while developing.

However, both run into the same issue that certain files are not being watched properly and do not use saved changes unless I manually run npm run build first.

Here is my package.json:

{
  "scripts": {
    "start": "ts-node-dev src/server/index.ts",
    "build": "rimraf ./build && tsc",
    "format": "prettier --write \"**/*.ts\""
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "knex": "^0.21.14",
    "module-alias": "^2.2.2",
    "morgan": "^1.10.0",
    "passport": "^0.4.1",
    "passport-google-oauth2": "^0.2.0",
    "pg": "^8.5.1"
  },
  "devDependencies": {
    "@types/body-parser": "^1.19.0",
    "@types/express": "^4.17.8",
    "@types/knex": "^0.16.1",
    "@types/morgan": "^1.9.2",
    "@types/node": "^14.14.6",
    "@types/passport": "^1.0.4",
    "@types/passport-google-oauth2": "^0.1.3",
    "prettier": "^2.2.1",
    "rimraf": "^3.0.2",
    "ts-node-dev": "^1.1.1",
    "typescript": "^4.0.5"
  },
  "_moduleAliases": {
    "@db": "build/server/db"
  }
}

This is my tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./build",
    "esModuleInterop": true,
    "strict": true,
    "baseUrl": "./src",
    "paths": {
      "@db/*": ["server/db/*"]
    }
  },
  "include": [
    "src"
  ]
}

It properly reloads with saved changes with most files but not src/server/db/models/voter.ts. I suspect that it might have something to do with module-alias because that file is being imported as import Voter from '@db/models/voter'. I am not sure what the solution is though because I don't run into any compile or runtime errors, and things work after manually running npm run build.

File Directory

hopelessmuffins
  • 315
  • 1
  • 11
  • Facing similar issue , auto reload seems to work on top level files included in src but not on path like /src/**/* etc. Were you able to resolve this? – fatcook May 14 '21 at 06:45

0 Answers0