You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No output with --out when using import statement #1544
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:
/// <reference path="./typings/node/node.d.ts"/>
/// <reference path="./typings/lodash/lodash.d.ts"/>
import _ = require("lodash");
var x = "test";
and I used tsc --module commonjs --out app.js app.ts to compile, I would get no output at all
To get my output back, I would either need to drop the import statement or drop the --out argument.
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
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 --module commonjs and --out are conceptually mutually exclusive, I would appreciate the compiler warning me. It is not obvious.
--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.
This is a special case though, i am fine with a warning. what is the proposal?
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 --out. Maybe the problem is the implicit nature of what is considered "external" and "internal". The simple presence of a keyword changes my file from being one or the other. That had me really confused until I clicked on to it.
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.
With #5090 merged this is resolved. It is now an error to specify --out with --module unless --module is amd or system, at which point the modules will be concatenated into the specified output file.
When I use module: system with out: app.js, I get the output in the the cwd/the cwd, like ~/Repositories/app/Users/Jason/Repositores/app. See ivogabe/gulp-typescript#123
Wesley Wigham (@weswigham) im still facing the same problem as the others tsc main.ts --out main.js
`will still output an empty file with no warning what so ever...
Frédéric Camblor (@fcamblor) this issue was reported in #8634 and you should now see an error if you do not have --module specified with --outFile. the fix is available in typescript@next.
@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.
Activity
panost commentedon Dec 21, 2014
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
felixSchl commentedon Dec 21, 2014
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
--module commonjsand--outare conceptually mutually exclusive, I would appreciate the compiler warning me. It is not obvious.danquirk commentedon Jan 6, 2015
Seems reasonable to give some sort of warning/error here.
RyanCavanaugh commentedon Jan 8, 2015
I thought we had disallowed this in 1.0, but apparently that is not the case.
mhegazy commentedon Jan 8, 2015
--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.
This is a special case though, i am fine with a warning. what is the proposal?
danquirk commentedon Jan 8, 2015
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.
felixSchl commentedon Jan 8, 2015
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
--out. Maybe the problem is the implicit nature of what is considered "external" and "internal". The simple presence of a keyword changes my file from being one or the other. That had me really confused until I clicked on to it.danquirk commentedon Jan 8, 2015
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.
felixSchl commentedon Jan 8, 2015
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.
panost commentedon Jan 14, 2015
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.
13 remaining items
weswigham commentedon Nov 11, 2015
With #5090 merged this is resolved. It is now an error to specify
--outwith--moduleunless--moduleisamdorsystem, at which point the modules will be concatenated into the specified output file.jasonszhao commentedon Nov 27, 2015
When I use
module: systemwithout: app.js, I get the output in the the cwd/the cwd, like~/Repositories/app/Users/Jason/Repositores/app. See ivogabe/gulp-typescript#123h-nazzal commentedon Mar 11, 2016
Wesley Wigham (@weswigham) im still facing the same problem as the others
tsc main.ts --out main.js`will still output an empty file with no warning what so ever...
mhegazy commentedon Mar 11, 2016
H.Nazzal (@h-nazzal) you need
--module amdor--module systemGarryFlemings commentedon May 29, 2016
Ryan Cavanaugh (@RyanCavanaugh) Daniel Rosenwasser (@DanielRosenwasser) I'm unfamiliar with Git statuses. I see "Fixed" and "Closed". I see Milestone for TypeScript 1.8, which is out. I see "Wesley Wigham (@weswigham) was unassigned by Candice Wright (@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 Meirion Hughes (@MeirionHughes) is having the same problem. Should someone open another ticket to get this considered again? And cite this one?
fcamblor commentedon May 31, 2016
FYI (and because I spent an hour on this as well), if you :
tsconfig.jsonfor your compilation, useoutFileand not define anymoduleentry in the filegrunt-tsor Intellij IDEA Compiler to compile typescript from thetsconfigThen, your resulting
app.jswill be empty as well.Workaround : put a
moduleentry in yourtsconfig.jsonfileNote: I only tested with
grunt-tsandIntelliJ IDEA, but maybe other tool may be concerned by this problem as well.mhegazy commentedon May 31, 2016
Frédéric Camblor (@fcamblor) this issue was reported in #8634 and you should now see an error if you do not have
--modulespecified with--outFile. the fix is available intypescript@next.mhegazy commentedon May 31, 2016
@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.