-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
No output with --out when using import statement #1544
Comments
I already asked this here http://stackoverflow.com/questions/27547972/typescript-empty-output-file-when-compiling If you have a top level "import" statement compiler goes to "external module" mode. In your case it correctly generates the app.js, but then it's been overriden an empty app.js. Since you have one single file as input, you can fix this by removing the "--out" switch While I understand why this happens, I don't find it any helpfull, specially if you are creating a node app and not an external module. One workaround is to use "var" instead of the "import" statement, but you will loose all VStudio intellisense |
I don't mind that, but you also lose your type safety. The compiler doesn't associate the d.ts file with the require statement and hence you don't get type safety and intellisense. If |
Seems reasonable to give some sort of warning/error here. |
I thought we had disallowed this in 1.0, but apparently that is not the case. |
--out will only apply to global code. Consider the case of a project with a loader and a set of modules. the loader.js is the only piece included in the html file, the other module files are imported dynamically by the loader. --out loader.js will build the non-external module pieces into one file, the other module files will be emitted to their own files. |
In the case where --out is specified and the emitted file has no content emitted we should warn something to the effect of: "Warning: output file is empty." I'm not sure we want the message to say anything more speculative (about combining it with external modules), presumably anyone searching for this error will quickly find a thread here or on StackOverflow with an explanation. |
That's something, but also pretty vague. I could just have compiled an empty file to start with. It's not giving me an indication as to why - I would still be baffled to find nothing in the output file after specifying |
Yeah, that's a common source of confusion, but it's also not something that's really amenable to being quickly explained in a command line error message. An explicit warning at least gives you an immediate clue something is awry and some text to key your search for answers off of. Open to suggestions for alternatives though. |
Maybe it really just comes down to having better docs on the topic. I have read the official docs a couple of times to try to understand it, but it was a rather painful experience. The information is lacking and key points are not driven home. The section on modules starts of writing some module code, which by the looks of it would classify as an "internal" module - but really in my opinion it should explain the module infrastructure first - tell me what "internal" and "external" is supposed to be, because the words themselves don't do a good job at it. Then the next section patronises me and tells me the benefits of modules. Let alone the code used in the example is simply unconcise and distracting from the point. I apologize for the rant, but the more I think about it, a simple warning message as suggested above, coupled with a solid documentation upgrade would be a worthwhile effort. I would be willing to create a pull request for it, if there's a repo for the docs. |
Given that one of TS goals, is the ease of development of large apps and large apps are always split into many files, then maybe when --out is specified the compiler does exactly what is told, Produce a single output file, merging all modules with the same name to one and raising errors when a conflict is found (ie private var with the same name). The current behaviour (produce a file for each input) then, can be easily achieved by calling the compiler without the --out flag or execute it multiple times. |
Approved. Spitballed solution in backlog meeting was to move the current behavior under an experimental flag ( We actually have no idea how many people are doing this on purpose but believe it to be extremely small. If somehow you find yourself looking at this issue and mix |
If we do not allow --out with --module, then all non-module files (i.e. no top level import/export) should be coerced in a module output. see #2937 for more details. |
Hi – I just posted a dup of this (#3950) after losing a lot of time tracking it down. It looks like there are other people who have had similar issues. I would strongly 👍 throwing an error or at least logging a warning in this case. If you just log a warning, then at least people can search for that text string and find the docs you write about it, and start to understand what's going on. |
As a newbie to TS I found this very confusing.... |
Just wanna add my +1 to this. Just cost me 2 hours that a warning would have saved. I really like to think of the compilers I use as being on my side, rather than providing a language aptitude test. |
Just want to +1 this, starting with TS and it's infuriating for this to happen. Not impressed. |
With #5090 merged this is resolved. It is now an error to specify |
When I use |
@weswigham im still facing the same problem as the others |
@h-nazzal you need |
See microsoft/TypeScript#1544 for more information on why --out was unacceptable with modules.
@RyanCavanaugh @DanielRosenwasser I'm unfamiliar with Git statuses. I see "Fixed" and "Closed". I see Milestone for TypeScript 1.8, which is out. I see "@weswigham was unassigned by @capfei on Jan 20". All that's consistent. On the other hand, I see indication above from @jasonszhao that the problem remains. And I see discussion today on https://gitter.im/Microsoft/TypeScript possibly indicating that @MeirionHughes is having the same problem. Should someone open another ticket to get this considered again? And cite this one? |
FYI (and because I spent an hour on this as well), if you :
Then, your resulting Workaround : put a Note: I only tested with |
@Prairie-Falcon this feature was implemented for TS 1.8, and should be available today. if you are running into issues, please file a new ticket, and provide enough information to allow us to diagnose the issue. |
This cost me quite a bit of time, so please enlighten me if this is anticipated behaviour and let's put a big note in the docs.
tsc --module commonjs --out app.js app.ts
type checks correctly, however produces no output. In fact it does not produce output with--module amd
either.tsc --module commonjs app.ts
type checks correctly and produces output, but I do not have control over the location of the output.For reference, I am developing a node app.
Let's say my app looks like this:
and I used
tsc --module commonjs --out app.js app.ts
to compile, I would get no output at allTo get my output back, I would either need to drop the
import
statement or drop the--out
argument.This is happening on version 1.3.0.0
The text was updated successfully, but these errors were encountered: