{"id":26653,"library":"webpack-sane-compiler","title":"webpack-sane-compiler","description":"A thin wrapper around webpack's compiler that provides a friendlier, event-based API with Promises, explicit begin/end/error/invalidate events, and automatic error handling for compilation failures. Version 3.1.1 supports webpack 2, 3, and 4 (webpack >=2.0.0 <5.0.0). Differentiates from raw webpack by rejecting Promises and calling watch handlers with errors when stats contain errors, plus emitting additional lifecycle events like 'begin' and 'invalidate'. Package is stable and mature with no recent releases.","status":"maintenance","version":"3.1.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/moxystudio/webpack-sane-compiler","tags":["javascript","webpack","compiler","compilation"],"install":[{"cmd":"npm install webpack-sane-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-sane-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-sane-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required to work with webpack compiler","package":"webpack","optional":false}],"imports":[{"note":"Package is CJS default-exported, but ESM import works with bundlers. Avoid named imports.","symbol":"default","correct":"import saneWebpack from 'webpack-sane-compiler'"},{"note":"CommonJS require is the primary usage pattern.","symbol":"require","correct":"const saneWebpack = require('webpack-sane-compiler')"}],"quickstart":{"code":"const webpack = require('webpack');\nconst saneWebpack = require('webpack-sane-compiler');\n\nconst webpackCompiler = webpack({\n  entry: './src/index.js',\n  output: { path: __dirname + '/dist', filename: 'bundle.js' }\n});\n\nconst compiler = saneWebpack(webpackCompiler);\n\ncompiler\n  .on('begin', () => console.log('Compilation started'))\n  .on('end', ({ stats, duration }) => {\n    console.log(`Compilation finished successfully (${duration}ms)`);\n  })\n  .on('error', (err) => {\n    console.log('Compilation failed:', err.message);\n  });\n\n// Run once\ncompiler.run()\n  .then(({ stats, duration }) => {\n    console.log('First compile:', duration, 'ms');\n  })\n  .catch(err => console.error('Run error:', err.message));\n\n// Or watch\nconst invalidate = compiler.watch({ aggregateTimeout: 300 }, (err, { stats, duration }) => {\n  if (err) console.error('Watch error:', err.message);\n  else console.log('Watch compiled in', duration, 'ms');\n});\n\n// After some changes\nsetTimeout(() => invalidate(), 5000);","lang":"javascript","description":"Creates a webpack compiler, wraps it with sane-compiler, then demonstrates both .run() and .watch() usage with event listeners."},"warnings":[{"fix":"Always handle the error parameter in watch callback; do not ignore it.","message":"The .watch() handler gets called with an error object if stats contain errors, unlike native webpack where you must check stats.hasErrors()","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Wrap in try/catch or use .catch() to handle rejection. Check err.stats for details.","message":".run() rejects the Promise if the compilation has errors, even though webpack's run() returns a stats object with errors embedded","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Consider using webpack's built-in Compiler with hooks or migrate to 'webpackbar' or 'friendly-errors-webpack-plugin' for more modern workflows.","message":"Package is in maintenance mode; no new features have been added since 2018. Limited compatibility with webpack 5.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use webpack version <5.0.0 as per peer dependency. Alternatively, upgrade to a fork that uses hooks.","cause":"Webpack 4+ deprecates plugin() method; the wrapper may still call it internally.","error":"TypeError: webpackCompiler.plugin is not a function"},{"fix":"Add .catch() to handle rejection: compiler.run().catch(err => console.error(err.message, err.stats))","cause":".run() rejects the Promise on compilation errors if not caught.","error":"UnhandledPromiseRejectionWarning: Error: Compilation failed with 1 error(s)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}