Skip to content

tsc -w should not recompile if a file is created into an excluded folder #27279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rolivegab opened this issue Sep 21, 2018 · 20 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@rolivegab
Copy link

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.

@sheetalkamat
Copy link
Member

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 sheetalkamat added By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Working as Intended The behavior described is the intended behavior; this is not a bug and removed By Design Deprecated - use "Working as Intended" or "Design Limitation" instead labels Sep 26, 2018
@xtrinch
Copy link

xtrinch commented Dec 1, 2019

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

@divvjson
Copy link

divvjson commented Dec 6, 2019

Would very much appreciate some solution to this as well.

@paramaggarwal
Copy link

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.

@128keaton
Copy link

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.

@rettgerst
Copy link

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

@massimeddu
Copy link

Same issue here. Anyone is able to solve this?

@ckanthony
Copy link

same here

@peresbruno
Copy link

peresbruno commented Apr 3, 2020

Same issue here. With Nest.js.

@JiProchazka
Copy link

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

Exactly the same issue with LevelDB and NestJS

@darkyelox
Copy link

darkyelox commented May 8, 2020

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

@helmerdx
Copy link

Same issue here. With Nest.js.

#27279 (comment)

Solved it.

And put your upload directory inside of dir for example.

@mankittens
Copy link

mankittens commented Jun 22, 2020

The approach in #27279 does not resolve this issue for me.

I'm running tsc -w and webpack side-by-side, with tsc purely checking for ts errors and webpack producing a js bundle.

Every time webpack places a new hot-update.js or hot-update.json file in the build folder, that triggers tsc to recompile. I've confirmed this with the --exendedDiagnostics flag:

DirectoryWatcher:: Triggered with /Users/{redacted}/GitHub/{redacted}/packages/{redacted}/build/main.852665aec4d5e06ecc09.hot-update.js

My tsconfig:

{
  ...
  "include": ["packages/*/src/**/*"]
}

Please give us a way to control which files can or cannot trigger a recompile!

@sean9999
Copy link

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.

@thallada
Copy link

I'm hopeful that #39030 will fix this (merged, but not released yet).

@DanazSdiq
Copy link

DanazSdiq commented Aug 2, 2020

If anyone is still facing the same issue, I solved this by adding the include option in my tsconfig.json to only watch those directories without the static files. An example:
"include": [ "src" ]
At the moment, the exclude option does not work.

@liv1n9
Copy link

liv1n9 commented Oct 21, 2020

It doesn't work for me
tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "resolveJsonModule": true,
    "strictNullChecks": false,
  },
  "exclude": ["node_modules", "dist", "data", "uploads"],
  "include": ["src"]
}

data is docker mount volumes and uploads is file upload folder

@max-sv-ma
Copy link

max-sv-ma commented Apr 11, 2021

having same issue.

"include": [
    "src/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "build/**/*.js",
    "tempDataStore/*"
  ]}

even tho the files are being generated within tempDataStore which is outside src. project still being recompiled
ts version 3.9.7

@dawsnap
Copy link

dawsnap commented Sep 23, 2021

Same happening here with Nest.js. Writing a buffer into a file will make the whole project to recompile thus cutting the writing process. So irritating.

My solution was using a hidden folder /.downloads/ That way it is excluded by default, in case that helps anyone!

@fabstu
Copy link

fabstu commented Jul 11, 2024

Ignoring mydb.sqlite-journal worked for me with excludeFiles in tsconfig.json. My issue was that another package using the database package triggered the depenency, and so had to use .. to navigate to the files that triggered the change.

Used tsc --watch --extendedDiagnostics to see the files that triggered the rebuild.

	"watchOptions": {
		"excludeFiles": [
			"prisma/mydb.sqlite-journal",
			"../database/prisma/mydb.sqlite-journal",
			"../../node_modules/@repo/db/prisma/mydb.sqlite-journal",
			"**/mydb.sqlite-journal"
		]
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests