Skip to content

No output with --out when using import statement #1544

Closed

Description

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.

This is happening on version 1.3.0.0

Activity

  1. panost commented on Dec 21, 2014

    @panost

    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

  2. felixSchl commented on Dec 21, 2014

    @felixSchl
    Author

    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.

  3. danquirk commented on Jan 6, 2015

    @danquirk
    Member

    Seems reasonable to give some sort of warning/error here.

  4. RyanCavanaugh commented on Jan 8, 2015

    @RyanCavanaugh
    Member

    I thought we had disallowed this in 1.0, but apparently that is not the case.

  5. mhegazy commented on Jan 8, 2015

    @mhegazy
    Contributor

    --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?

  6. danquirk commented on Jan 8, 2015

    @danquirk
    Member

    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.

  7. felixSchl commented on Jan 8, 2015

    @felixSchl
    Author

    Warning: output file is empty.

    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.

  8. danquirk commented on Jan 8, 2015

    @danquirk
    Member

    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.

  9. felixSchl commented on Jan 8, 2015

    @felixSchl
    Author

    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.

  10. panost commented on Jan 14, 2015

    @panost

    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.

  11. added this to the milestone on Apr 27, 2015
  12. 13 remaining items

  13. weswigham commented on Nov 11, 2015

    @weswigham
    Member

    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.

  14. jasonszhao commented on Nov 27, 2015

    @jasonszhao

    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

  15. h-nazzal commented on Mar 11, 2016

    @h-nazzal

    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...

  16. mhegazy commented on Mar 11, 2016

    @mhegazy
    Contributor

    H.Nazzal (@h-nazzal) you need --module amd or --module system

  17. GarryFlemings commented on May 29, 2016

    @GarryFlemings

    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?

  18. fcamblor commented on May 31, 2016

    @fcamblor

    FYI (and because I spent an hour on this as well), if you :

    • Rely on tsconfig.json for your compilation, use outFile and not define any module entry in the file
    • Use either grunt-ts or Intellij IDEA Compiler to compile typescript from the tsconfig

    Then, your resulting app.js will be empty as well.

    Workaround : put a module entry in your tsconfig.json file

    Note: I only tested with grunt-ts and IntelliJ IDEA, but maybe other tool may be concerned by this problem as well.

  19. mhegazy commented on May 31, 2016

    @mhegazy
    Contributor

    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.

  20. mhegazy commented on May 31, 2016

    @mhegazy
    Contributor

    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?

    @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.

  21. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions