andreypopp / typescript-loader

[DEPRECATED] TypeScript Webpack Plugin
https://github.com/andreypopp/typescript-loader
MIT License
81 stars 10 forks source link

Throw error code when build fails #21

Open ChimeraCoder opened 9 years ago

ChimeraCoder commented 9 years ago

When using typescript-loader with webpack, failed compilations cause an exit code of 0 to be returned, even when the --bail flag is set on webpack (which is soon going to be switched to the default behavior: https://github.com/webpack/webpack/issues/708).

This breaks build tools like make and Docker, which use exit codes to determine whether a process encountered an error or not.

screenshot - 04222015 - 10 28 26 am

andreypopp commented 9 years ago

Does the problem manifest itself when there's no typescript-loader in play? Asking because typescript-loader report errors via webpack API and I don't really what I'm doing wrong there...

ChimeraCoder commented 9 years ago

Yes, without the typescript loader, I get a non-zero exit status.

Here's an example: if you take a look at https://github.com/ChimeraCoder/go-react-jetpack (current master is 234b358a245ac2b32855e2ef19a06fbe7cc63969), and add var foo = continue; or some other syntactic error to the top of typescript/app.ts. make will fail, but the exit code returned is zero (success):

screenshot - 04242015 - 10 57 35 am

In this screenshot I'm running it inside a Docker container, but it fails on my local machine in the same way. If the tsd libraries aren't all installed in the right location under typescript, though, it will fail with exit code 2, which I believe is from webpack. If you want to reproduce this and have Docker installed, the easiest way is probably to run the docker container with docker build -t jetpack . && docker run -it -p 8080:8080 jetpack /bin/bash, or you can look at the Dockerfile to see the commands for setting it up locally outside a container. (It's a little more than an npm install . because it requires some stuff from tsd, and I haven't streamlined the build process yet).

If you take a look at the typescript-loader-error-example branch, though, (currently at ce79040405892d35cab273137b795a365f622c68) I've replaced the webpack.config file with one that doesn't use the Typescript loader and added an app.js which will be a syntactic error. Sure enough, this fails with a non-zero exit code (indicating failure).

screenshot - 04242015 - 11 11 31 am

If you don't have Docker and are having trouble reproducing this, let me know, but I think this should be enough to start with.

binarious commented 8 years ago

The solution provided in https://github.com/webpack/webpack/issues/708 by TiddoLangerak works for me: https://github.com/TiddoLangerak/webpack-fail-plugin