FailOnErrorsPlugin
raw JSON → 3.0.0 verified Sat Apr 25 auth: no javascript
Webpack plugin that forces the build process to exit with a non-zero exit code (status code 1) when compilation has any errors or warnings, superseding the default behavior where Webpack only fails on hard errors. Version 3.0.0 supports Webpack 4+. Useful for CI/CD pipelines to catch soft errors and warnings that would otherwise pass the build. A maintained fork of the abandoned webpack-fail-plugin.
Common errors
error TypeError: FailOnErrorsPlugin is not a constructor ↓
cause Using import instead of require; the package is CommonJS only.
fix
Replace 'import FailOnErrorsPlugin from ...' with 'const FailOnErrorsPlugin = require(...)'
error ValidationError: Invalid options object. FailOnErrorsPlugin has been initialized using an options object that does not match the API schema. ↓
cause Passing multiple arguments instead of a single options object.
fix
new FailOnErrorsPlugin({ failOnErrors: true, failOnWarnings: true })
error Error: Cannot find module 'fail-on-errors-webpack-plugin' ↓
cause Package not installed or version mismatch (e.g., used with npm/yarn and not present).
fix
Run 'npm install fail-on-errors-webpack-plugin --save-dev'
Warnings
breaking Forked from webpack-fail-plugin; API changed from constructor arguments to options object. ↓
fix Pass an object { failOnErrors: boolean, failOnWarnings: boolean } instead of positional arguments.
deprecated Webpack 5 support is experimental; no official statement. ↓
fix Test with Webpack 5; consider alternatives like webpack-stats-plugin or built-in emitError/emitWarning.
gotcha If both failOnErrors and failOnWarnings are false, plugin does nothing; process will still exit 0 on errors/warnings. ↓
fix Set at least one option to true to get the desired behavior.
gotcha Plugin uses process.on('exit') to set process.exitCode = 1; may conflict with other exit handlers. ↓
fix Be careful when combining with other plugins that manipulate exit codes.
Install
npm install fail-on-errors-webpack-plugin yarn add fail-on-errors-webpack-plugin pnpm add fail-on-errors-webpack-plugin Imports
- FailOnErrorsPlugin wrong
import FailOnErrorsPlugin from 'fail-on-errors-webpack-plugin';correctconst FailOnErrorsPlugin = require('fail-on-errors-webpack-plugin'); - Options wrong
import { Options } from 'fail-on-errors-webpack-plugin';correcttypedef {Object} Options # {failOnErrors?: boolean, failOnWarnings?: boolean} - FailOnErrorsPlugin (new) wrong
new FailOnErrorsPlugin(true, true)correctnew FailOnErrorsPlugin({ failOnErrors: true, failOnWarnings: true })
Quickstart
// webpack.config.js
const FailOnErrorsPlugin = require('fail-on-errors-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: { filename: 'bundle.js' },
plugins: [
new FailOnErrorsPlugin({
failOnErrors: true,
failOnWarnings: true,
})
]
};