tslint-loader icon indicating copy to clipboard operation
tslint-loader copied to clipboard

Fail the webpack build on lint errors

Open hodavidhara opened this issue 7 years ago • 7 comments

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.

hodavidhara avatar Jun 29 '17 18:06 hodavidhara

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.

0xNacho avatar Jun 30 '17 08:06 0xNacho

Same for me, does not work

apastuhov avatar Dec 19 '17 21:12 apastuhov

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

andelizondo avatar Jan 19 '18 14:01 andelizondo

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.')
  }
});

decates avatar Jan 23 '18 10:01 decates

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.

gregkopp avatar Apr 11 '18 15:04 gregkopp

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

apastuhov avatar Apr 19 '18 06:04 apastuhov

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

fgerschau avatar Nov 13 '18 12:11 fgerschau