0

I am using TypeScript to create my nodejs application, which is working fine inasmuch as the index.ts is being compiled and executed successfully, but the TypeScript files in subfolders are being ignored and don't form part of the dev watch.

Can anyone help out? I use yarn start to run my app in dev mode. My scripts from package.json look like this:

"scripts": {
  "start": "yarn run build:live",
  "build": "rm -rf dist && tsc",
  "build:live": "nodemon --exec ./node_modules/.bin/ts-node -- ./src/index.ts"
}

And my tsconfig.json looks like this:

{
  "compilerOptions": {
    "outDir": "dist",
    "target": "es2017",
    "module": "commonjs",
    "sourceMap": true,
    "noUnusedLocals": true,
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "src/**/**.ts",
    "test/**/**.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

I have tried using "build:live": "nodemon --exec ./node_modules/.bin/ts-node --project tsconfig.json" as my dev script but this causes the compiler to hang.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
serlingpa
  • 12,024
  • 24
  • 80
  • 130

1 Answers1

0

ts-node will only execute files that are transitively required or imported by your main file src/index.ts. You can use the --files option to make it include all files specified in tsconfig.json in the compilation, but this only helps to declare things, not to define them at runtime. See the documentation. If you need to execute all files without using require or import, consider running your project using a different tool.

Matt McCutchen
  • 28,856
  • 2
  • 68
  • 75