TypeScript: tsc -w should not recompile if a file is created into an excluded folder

Search Terms: tsc -w watch exclude subfolder recompile

tsconfig.json

  "compilerOptions": {
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "lib": ["es7"],                             /* Specify library files to be included in the compilation. */
    "sourceMap": true,                     /* Generates corresponding '.map' file. */
    "outDir": "dist",                        /* Redirect output structure to the directory. */
    "rootDir": "src",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "allowSyntheticDefaultImports": true,     /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
    "esModuleInterop": true,                  /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "watch": true,
  },
  "exclude": [
    "node_modules",
    "dist",
    "upload",
  ]
}

Folder structure image

Expected behavior: When i create a file into upload/, tsc should not detect file changes.

Actual behavior:

When i create a file into upload/, server detects file changes and do incremental compilation. i’m using "tsc-watch --onSuccess \"node dist/server.js\"", so, my server is restarted whenever user upload a file. image

Is there any way to tsc -w not detect file creation in an excluded project’s subfolder?

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 19 (1 by maintainers)

Most upvoted comments

This is by design. Normally even though file is excluded by the config file, it could get included by module resolution and could be missing. So we cant just ignore file addition or removal of file in exclude directory.

Any proposals on how to solve the problem, if this is by design so? It’s still a problem, makes file upload testing impossible with watch

Same issue here. With Nest.js.

I have the same problem with Nest JS, and no solution for this is making the development for certain cases like simple file upload a real pain.

There is a solution in this comment

This is by design. Normally even though file is excluded by the config file, it could get included by module resolution and could be missing. So we cant just ignore file addition or removal of file in exclude directory.

@sheetalkamat the excluded file should be part of the build, yes - but it should not trigger a rebuild on change if it is excluded.

Would very much appreciate some solution to this as well.

also experiencing this issue, also with nest - we are using sqlite and any database update is triggering a rebuild and thus a server restart.

I’ve been dealing with this issue on two separate projects. Nest uses tsc --watch internally for their build triggering, and I’d love to have a folder NOT trigger a rebuild of a project. Super irritating.

this seems poorly designed. I do not think the stated reason is sufficient. shift the burdon/power to the developers by allowing this exclusion in watch mode.