Registry / devops / webpack-sane-compiler

webpack-sane-compiler

JSON →
library3.1.1jsnpmunverified

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.

npm install webpack-sane-compiler
INSTALL
IMPORT
SIG · WEBPACK-SANE-COMPI
W
webpack-sane-compiler
devopsjavascriptv3.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import saneWebpack from 'webpack-sane-compiler'
Package is CJS default-exported, but ESM import works with bundlers. Avoid named imports.
require
const saneWebpack = require('webpack-sane-compiler')
CommonJS require is the primary usage pattern.

Creates a webpack compiler, wraps it with sane-compiler, then demonstrates both .run() and .watch() usage with event listeners.

const webpack = require('webpack'); const saneWebpack = require('webpack-sane-compiler'); const webpackCompiler = webpack({ entry: './src/index.js', output: { path: __dirname + '/dist', filename: 'bundle.js' } }); const compiler = saneWebpack(webpackCompiler); compiler .on('begin', () => console.log('Compilation started')) .on('end', ({ stats, duration }) => { console.log(`Compilation finished successfully (${duration}ms)`); }) .on('error', (err) => { console.log('Compilation failed:', err.message); }); // Run once compiler.run() .then(({ stats, duration }) => { console.log('First compile:', duration, 'ms'); }) .catch(err => console.error('Run error:', err.message)); // Or watch const invalidate = compiler.watch({ aggregateTimeout: 300 }, (err, { stats, duration }) => { if (err) console.error('Watch error:', err.message); else console.log('Watch compiled in', duration, 'ms'); }); // After some changes setTimeout(() => invalidate(), 5000);
Debug
Known issues
gotchaThe .watch() handler gets called with an error object if stats contain errors, unlike native webpack where you must check stats.hasErrors()
fix
Always handle the error parameter in watch callback; do not ignore it.
affects: >=3.0.0
gotcha.run() rejects the Promise if the compilation has errors, even though webpack's run() returns a stats object with errors embedded
fix
Wrap in try/catch or use .catch() to handle rejection. Check err.stats for details.
affects: >=2.0.0
deprecatedPackage is in maintenance mode; no new features have been added since 2018. Limited compatibility with webpack 5.
fix
Consider using webpack's built-in Compiler with hooks or migrate to 'webpackbar' or 'friendly-errors-webpack-plugin' for more modern workflows.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: webpackCompiler.plugin is not a function
Webpack 4+ deprecates plugin() method; the wrapper may still call it internally.
fix
Use webpack version <5.0.0 as per peer dependency. Alternatively, upgrade to a fork that uses hooks.
UnhandledPromiseRejectionWarning: Error: Compilation failed with 1 error(s)
.run() rejects the Promise on compilation errors if not caught.
fix
Add .catch() to handle rejection: compiler.run().catch(err => console.error(err.message, err.stats))
Upgrade
Version history
3.1.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency required to work with webpack compiler
Agent activity
4 hits · last 30 days
node
4
Resources
webpack-sane-compiler — npm install webpack-sane-compiler · libregistry