webpack-validator

raw JSON →
3.0.1 verified Sat Apr 25 auth: no javascript maintenance

Validate your webpack configs using joi schema. Provides static type checking, spell checking, and semantic validations (e.g., preventing simultaneous use of loader and loaders). Current stable version is 3.0.1. The package is in maintenance mode: webpack v2+ has built-in validation, so this package only supports webpack v1. Last update in 2017, with no active development. Key differentiator: it catches errors like misspelled loader names or incorrect plugin usage via a schema-based validation.

error Error: Cannot find module 'joi'
cause joi is a peer dependency not automatically installed.
fix
Run 'npm install joi' alongside webpack-validator.
error ValidationError: child "module" fails because [child "loaders" fails because ["loaders" must be an array]]
cause The 'loaders' property must be an array, but a string was provided.
fix
Change 'loaders: "babel-loader"' to 'loaders: ["babel-loader"]'.
error TypeError: validate is not a function
cause Using .default when requiring in CommonJS (common with ES6 interop).
fix
Use 'const validate = require('webpack-validator');' without .default.
breaking Version 3.0.0 throws an error when webpack 2 is installed alongside.
fix Use webpack v1 or remove webpack-validator if using webpack v2+ (which has built-in validation).
deprecated The package is in maintenance mode and not actively developed. Webpack v2+ includes built-in config validation.
fix Migrate to webpack v2+ and use its built-in validation, or continue using this package for webpack v1 only.
gotcha The schema may not cover all custom webpack options (e.g., custom plugins). Use the '--schema' CLI option to extend.
fix Provide a custom schema via the second argument to validate() or use the CLI --schema flag.
breaking In v2.2.5, the exposed API changed (fix regression). Ensure you're using the correct export.
fix Use default export for single config, validateRoot for array configs.
npm install webpack-validator
yarn add webpack-validator
pnpm add webpack-validator

Shows how to import and use webpack-validator to validate a webpack v1 config, including an example with a common error.

// Install: npm install webpack-validator joi

const validate = require('webpack-validator');

// Example webpack config with a subtle error (loaders should be an array of strings)
const config = {
  entry: './app.js',
  output: {
    path: './dist',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }
    ]
  }
};

// Validate the config - will throw/display errors if invalid
const validConfig = validate(config);

// Webpack v1 users: place this in your webpack.config.js
module.exports = validate({ /* your config */ });