tslint-loader
tslint-loader copied to clipboard
Fail the webpack build on lint errors
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.
I have the same problem with webpack 1.x. This is how my tslint conf looks:
After running the build, it just shows warning messages instead of errors, so the build does not fail.
Same for me, does not work
Any update on this? Mine also doesn't make the build fail.
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.')
}
});
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 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"
In webpack 4, setting the emitErrors option to true was enough for me to fail the travis build.