wbuchwalter / tslint-loader

tslint loader for webpack
193 stars 65 forks source link

Fail the webpack build on lint errors #82

Open hodavidhara opened 7 years ago

hodavidhara commented 7 years ago

Is there a way to configure tslint-loader/webpack2 so that the entire webpack build will fail (return a non-0 exit code)? I tried with emitErrors: true and failOnHint: true but neither will fail the whole build.

0xNacho commented 7 years ago

I have the same problem with webpack 1.x. This is how my tslint conf looks: image

After running the build, it just shows warning messages instead of errors, so the build does not fail.

apastuhov commented 6 years ago

Same for me, does not work

andelizondo commented 6 years ago

Any update on this? Mine also doesn't make the build fail.

decates commented 6 years ago

In order to fail the build, I had to modify the code that runs webpack (2.6) to output the compilation errors and throw an error to actually fail the build. I think the point is that webpack simply runs the build, and outputs the results. In my build.js file I have something like the following, which correctly fails the build when emitErrors: true is set in the webpack config for tslint-loader:

const util = require('util');
...

webpack(webpackConfig, function (err, stats) {
  if (err) throw err;
  if (stats.compilation.errors && stats.compilation.errors.length > 0) {
    process.stdout.write(util.inspect(stats.compilation.errors));
    throw new Error('One or more webpack errors occurred, failing build.')
  }
});
gregkopp commented 6 years ago

Can you elaborate more on this solution, and how you incorporated this into package.json? I'm a webpack newbie but I need the build to fail on lint errors for our CI pipeline.

apastuhov commented 6 years ago

@gregkopp for CI you can run it as a separate command. And for local development you can run it as "prestart" or something like "lint && build"

fgerschau commented 5 years ago

In webpack 4, setting the emitErrors option to true was enough for me to fail the travis build.