webpack-format-messages
raw JSON →Beautiful formatting for Webpack messages, ported from Create React App. Version 3.0.1 is the current stable release, with TypeScript definitions and native ESM support via the `exports` map. This package extracts and prettifies Webpack error and warning messages from a stats object, providing clean console output similar to Create React App. It differs from `react-dev-utils/formatWebpackMessages` by accepting a Webpack stats object directly (not the toJson() output) and by being a lightweight standalone install (under 10 kB) without the heavy `react-dev-utils` dependency. Key differentiators: zero browser dependency, pure Node.js environment, and a simple API with two functions (`formatMessages` and `formatMessage`). Release cadence is sporadic; last major release was v3.0.0 with breaking changes to Node.js 13.0-13.7 support.
Common errors
error Cannot find module 'webpack-format-messages' ↓
npm install --save-dev webpack-format-messages error TypeError: formatMessages is not a function ↓
import formatMessages from 'webpack-format-messages' or const { formatMessages } = require('webpack-format-messages') error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported ↓
webpack-format-messages) or set type: 'module' in package.json. Warnings
breaking Node.js 13.0 - 13.7 users may experience import errors due to the `exports` map added in v3.0.0. ↓
deprecated Use of CommonJS require without destructuring may rely on the default export, which is deprecated in favor of named exports for clarity. ↓
gotcha The function expects a Webpack `stats` object, not the JSON from `stats.toJson()`. ↓
Install
npm install webpack-format-messages yarn add webpack-format-messages pnpm add webpack-format-messages Imports
- formatMessages wrong
const formatMessages = require('webpack-format-messages').defaultcorrectimport formatMessages from 'webpack-format-messages' - formatMessages wrong
const formatMessages = require('webpack-format-messages')correctconst { formatMessages } = require('webpack-format-messages') - formatMessage wrong
import formatMessage from 'webpack-format-messages'correctimport { formatMessage } from 'webpack-format-messages'
Quickstart
const webpack = require('webpack');
const formatMessages = require('webpack-format-messages');
const compiler = webpack({
// minimal config
entry: './src/index.js',
mode: 'development',
});
compiler.hooks.done.tap('report', (stats) => {
const messages = formatMessages(stats);
if (messages.errors.length) {
console.log('Errors:\n' + messages.errors.join('\n'));
}
if (messages.warnings.length) {
console.log('Warnings:\n' + messages.warnings.join('\n'));
}
});
compiler.run((err) => { if (err) console.error(err); });