-
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
--outFile is broken when module import is used #8634
Comments
Main.ts describes an external module with no exports. I'm not sure if that's what's causing your issue but you may want to look into that as you seem to be trying to export classes from it. |
Why an external module when it is defined via 'namespace' and no --module flag is used ? My original requirement is to have ServerWrapper in a separate .ts file, referenced via /// <reference in Main.ts and combined into a single js artifact that would define and invoke it (as opposed to require()-ing it at runtime) but it looks like it cannot be done even with a single .ts file with --outFile ? |
A module, as defined by the ES 2015 spec, is a file with a top level import or export. you do have one of these: by default the module system is As for the types issue, you will need to extract the types you are using from the module Hope that helps. |
Thanks for the explanation, this is somewhat unintuitive since |'m targeting es5 rather then es2015 (I believe that's the default but even when I specify it explicitly the behaviour is still the same) |
commonjs modules can not be concatenated. they do have different scopes, and that is enforced by the engine at runtime. the compiler will give you an error for using |
so it does: |
well.. i was a bit fuzzy when i said |
If each possibility (commonjs,none) when specified explicitly along with |
the reason is for backward compatibility. in the past the default was |
You mean there was a time when --outFile was legal for 'none'/'commonjs' ? Didn't that use to be '--out' ? |
the original behavior was a bit wacky :). so the original behavior is in the presence of |
So the empty js artifact is where the non-module code was supposed to be and since tsc implicitly decided to treat Main.ts as a commonjs module based on the presence of |
correct. |
Riiiight. |
i agree. |
I had no idea that was the case. It does seem quite confusing perhaps a compiler warning would help. |
Thanks! |
@mhegazy So just to be clear, in 2.0 only My use case is I'd like be able to use TypeScript |
@amcdnl: If you need a concatenated outfile with other module kinds (which is really just commonjs), I'd reccomend using browserify or webpack to do the job (we use browserify for the compiler itself at present). We prototyped an implementation of a commonjs bundler, but the maintanence burden was too high for something a bunch of other well-know tools already do really well. |
@weswigham understood, I ended up going with Rollup. Example: https://github.com/swimlane/angular2-data-table/blob/master/package.json#L34 Its probably worth just removing the option all together if thats the overall plan to reduce questions like these ;) |
TypeScript Version:
1.8.10
Node version :v4.2.2
OS: OSX
Code
Main.ts
Compile with
Expected behavior: (what is emitted as Main.js when --outFile is not specified)
Actual behavior:
The text was updated successfully, but these errors were encountered: