Skip to content

webpack exit code is equal to 0, if typescript build fails #108

Closed

Description

@marcelkottmann

When the build fails (i.e. at least one typescript compile error occured), the ts-loader emits an incomplete javascript file and does not propagate the build failure to webpack. When using webpack with the --bail command line option an compile error, should result in an webpack exit code not equal to zero.

Is there another way or option to check if a compile error occured.

Activity

  1. mpseidel commented on Nov 18, 2015

    @mpseidel

    +1 - this would be really helpful

    @PePe79 theoretically you could use the --noEmitOnError typescript option to get an exit code > 0 but then you only get something like this as an error message ModuleBuildError: Module build failed: Error: Typescript emitted no output for .../file.ts so none of the helpful ts compiler errors.

  2. marcelkottmann commented on Nov 18, 2015

    @marcelkottmann
    Author

    yes, i tried this already before, but this error message is not really useful.

    https://github.com/denvned/webpack-typescript does fail with exit code > 0 on compile error with webpack command line option --bail

    But this loader has other issues, so that's not an alternative for us and i would like to go on with ts-loader. But this bug is a blocker for our automated builds.

  3. jbrantly commented on Nov 18, 2015

    @jbrantly
    Member

    Yea, definitely know the need is there. Have you tried noEmitOnError (even though there are possibly issues with that - #91)?

  4. jbrantly commented on Nov 18, 2015

    @jbrantly
    Member

    Wow. I didn't get a lot of sleep and missed your comment on noEmitOnError. Sorry.

  5. denvned commented on Nov 18, 2015

    @denvned

    @PePe79, I would be happy to resolve any issues you have with webpack-typescript: https://github.com/denvned/webpack-typescript/issues

  6. MarkusKramer commented on Dec 23, 2015

    @MarkusKramer

    +1 would be really great if this was fixed. as incomplete error messages are obviously a big problem.

  7. EvAlex commented on Jan 21, 2016

    @EvAlex

    👍 unbeleivable! That's a blocker issue for using with build server!

  8. EvAlex commented on Jan 21, 2016

    @EvAlex

    @denvned, your loader has the same issue

  9. EvAlex commented on Jan 21, 2016

    @EvAlex

    Oh yeah, I've managed to fix it. I will create Pull Request and attach explaination there in 6-8 hours.

  10. raybooysen commented on Jan 21, 2016

    @raybooysen

    or @EvAlex @denvned @jbrantly combine to have a single loader, so we don't have all these disparate loaders. :)

  11. jbrantly commented on Jan 21, 2016

    @jbrantly
    Member

    Always open to PRs. FWIW, I think the correct solution to this is to fix #91 to be more useful and then combine that with --bail for the webpack exit code, but since I haven't actually dug in and tried it yet I don't know if there are problems with that approach.

  12. added a commit that references this issue on Jan 21, 2016
  13. vladimir-rovensky commented on Jan 29, 2016

    @vladimir-rovensky

    FWIW until this is fixed you can use something like webpack-fail-plugin to make your build fail on error.

  14. jbrantly commented on Jan 30, 2016

    @jbrantly
    Member

    OK, I've looked at this in more detail and here is where I've arrived:

    According to this, webpack2 should fix the exit code. They are not making the change to webpack1 for backward-compatibility reasons.

    I could make a change to ts-loader that would change the exit code in the case of failure. However, I feel like there are some issues with that, namely that a single loader would be taking on the responsibility of changing the exit code when there could be a lot of moving parts in the webpack config. For that reason it would at the very least need to be behind a flag. I could default the flag to "on" which would be a breaking change, and possibly could cause confusion when someone is trying to figure out why their build is all of a sudden failing. Or I could default to "off", which means you fine people looking for this functionality would have to configure it to "on" anyways.

    It seems to me a better solution is to recommend the webpack-fail-plugin suggested by @vladimir-rovensky. The source for that plugin seems completely reasonable, and I just tried it myself and it gets the job done. It's not that much more work to use that plugin than it would be to turn on a flag in ts-loader. All TypeScript errors are still printed without any changes to ts-loader. And when webpack2 hits the problem just goes away.

    If this seems reasonable I'll add some documentation pointing people to this solution.

  15. 23 remaining items

  16. gabro commented on Jul 10, 2017

    @gabro

    Hey @johnnyreilly is this issue still actual for modern versions of TypeScript?

    I tried to use the --noEmitOnError option of tsc (2.3+) and it appears to exit with code 1 and show meaningful errors.

  17. johnnyreilly commented on Jul 10, 2017

    @johnnyreilly
    Member

    I haven't tested lately and so I'm not sure.... Perhaps it's changed?

  18. gabro commented on Jul 10, 2017

    @gabro

    It seems like an option, this was discussed more than a year ago.
    What would be a quick way of testing it? Despite the readme, I've been recently surprised by this and accidentally deployed a broken bundle (in dev, thankfully)

  19. johnnyreilly commented on Jul 10, 2017

    @johnnyreilly
    Member

    I've just noticed that you said:

    I tried to use the --noEmitOnError option of tsc (2.3+) and it appears to exit with code 1 and show meaningful errors.

    You probably don't want to use this as it massively slows down compilation (can't emit until there are no errors at all)

    My guess is you still need to use the fail plugin to fail the build. I still am...

  20. gabro commented on Jul 10, 2017

    @gabro

    You're talking about incremental builds, right?

  21. johnnyreilly commented on Jul 10, 2017

    @johnnyreilly
    Member

    No - production builds. Errors show up just fine in incremental

  22. gabro commented on Jul 10, 2017

    @gabro

    Then I'm not sure I follow. Can you elaborate on how not emitting on errors slows down the build?

  23. johnnyreilly commented on Jul 10, 2017

    @johnnyreilly
    Member

    Sorry - I had my wires crossed there. Here's my workflow:

    • I develop in watch mode. Here I should notice errors either in the console or as a result of the error toast notification I have set up.
    • Our CI server runs the full build. Here the fail plugin will fail the build if there are any errors.

    What are you trying to do?

  24. gabro commented on Jul 10, 2017

    @gabro

    Same setup. However I initially missed the fail plugin note on the readme and the CI deployed a broken bundle that didn't make the build fail.

    I read this thread trying to understand why ts-loader doesn't propagate TS errors to webpack, and I stumbled upon the issue about --noEmitError not providing useful messages.
    That doesn't seem to be the case with recent versions of TS.

    I couldn't quite understand if there's other reasons of why errors are not propagated.

  25. johnnyreilly commented on Jul 10, 2017

    @johnnyreilly
    Member

    Well if you have the fail plugin in place now then you should be good. I can't actually remember anymore the details of why I'm afraid.... @jbrantly may be able to advise.

  26. gabro commented on Jul 10, 2017

    @gabro

    Yes, my CI is happy now.

    However, I suspect I'm not and I won't be the only one being bitten by this.

    Having the loader to propagate the errors to webpack is a reasonable expectation to have, so I'd like to understand what is the blocking issue.

  27. johnnyreilly commented on Jul 10, 2017

    @johnnyreilly
    Member

    I think this is more of a webpack rather than a ts-loader issue. I agree it's a reasonable expectation to have. There's more context here: webpack/webpack#708

  28. gabro commented on Jul 10, 2017

    @gabro

    Ah I see, thanks for the pointer.

  29. Lazarencjusz commented on Feb 16, 2018

    @Lazarencjusz

    Unfortunately, in my case, when I want to use thread-loader or happypack the webpack-fail-plugin not works (even I use new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }) plugin).

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions