Typescript: [tsc] Inform user when detected tsconfig.json file is not being applied

Created on 25 Jan 2016  路  9Comments  路  Source: microsoft/TypeScript

Under the following conditions...

  1. The tsc command is run directly on files, instead of a project.
  2. A tsconfig.json file is detected.

I'm requesting that the user be informed the detected tsconfig.json file is not being read, because the project is not being compiled. I'm not sure the best language for this message, but I'm envisioning something to this effect...

$ tsc foo.ts
[INFO] Detected tsconfig.json file, but it's not being applied, because you are targeting
individual files and not a project.
foo.ts(1,25): error TS1148: Cannot compile modules unless the '--module' flag is provided.

This would prevent issues like #6591, which I was having before.

Awaiting More Feedback Breaking Change Suggestion

Most helpful comment

Some people consider console output to be a breaking change #24123 (we don't)

It's a legitimate problem from the API perspective though; a build chain might reasonably be invoking tsc with an explicit list of files (we do this despite having tsconfig files, because our build setup is ancient) and interpret any output at all from the compiler to be an error state that should block the build.

All 9 comments

6600 might be the way to fixing this.

But in my case, there is no error with my tsconfig.json file. It's just not being read or used because I'm compiling an individual file, so I'm not sure how #6600 has anything to do with this.

this will be a breaking change, since existing projects today can have tsconfig but not use that in build.

but maybe at least give a warning from the compiler log which tsconfig is being applied, is there a flag?

Would have saved me a few hours if this message had been implemented.

As it stands I tried every possible combination of changes to tsconfig.json to make it work, only to eventually find out that tsconfig.json was being ignored because I am specifying the file to be compiled on the command line, which is really unexpected behaviour - "ah, you're specifying your input file? I see, well just to punish you for that, no tsconfig.json for you ha ha!"

@mhegazy this won't be a breaking change if we limit the fix to just informing the user which tsconfig file is being applied, as @aredfox suggested. Can we go that route at the very least? I'm not sure how a message would be a breaking change. It doesn't have to be an error or even a warning. Just inform us what's being applied, right?

Some people consider console output to be a breaking change #24123 (we don't)

It's a legitimate problem from the API perspective though; a build chain might reasonably be invoking tsc with an explicit list of files (we do this despite having tsconfig files, because our build setup is ancient) and interpret any output at all from the compiler to be an error state that should block the build.

I wonder if a verbose flag could be added to have it output this kind of information to keep it from being backwards incompatible? It could perhaps output the compiler options being used, and where it found the information.

To add an example on how this can confuse users now: I was specifying the input file via cli arg, and my build was failing. The error asked me to specify a compiler option (Try changing thelibcompiler option to es2015 or later). This _was already specified_ in my tsconfig.json, so I assumed I had a syntax or filename error in my tsconfig, or just did not understand how the option worked. I think i would have been lost quite a while if I didn't find this github issue!

As a TypeScript beginner this behavior really threw me off. It seems to be mentioned in only a single paragraph in tsconfig.json docs:

When input files are specified on the command line, tsconfig.json files are ignored.

This paragraph is not distinctive in any way so it's really easy to miss. It would be very helpful if that was emphasized somehow and if this info was added to tsc --help as well.

I'm sure there are many non-breaking things that can be done to make people aware of this usually unexpected behavior.

Btw, is there a way to run tsc on a certain file with tsconfig.json?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

manekinekko picture manekinekko  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments