{"id":20835,"library":"webpack-stats-plugin","title":"Webpack Stats Plugin","description":"A webpack plugin that ingests the compiler's stats object, transforms it, and writes a JSON file (typically 'stats.json') to the output directory. Version 1.1.3 is the current stable release, updated primarily with patch-level maintenance. Key differentiator: it is a dedicated, minimal stats-file writer without the overhead of full-featured analysis tools. It supports custom transforms (sync or Promise), selective field filtering, and works with webpack 4 and 5. Maintained by Formidable Labs.","status":"active","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/FormidableLabs/webpack-stats-plugin","tags":["javascript","webpack"],"install":[{"cmd":"npm install webpack-stats-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-stats-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-stats-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export via CommonJS. ESM support not provided; using a default import will fail.","wrong":"const StatsWriterPlugin = require('webpack-stats-plugin');","symbol":"StatsWriterPlugin","correct":"const { StatsWriterPlugin } = require('webpack-stats-plugin');"},{"note":"Named export. Default import yields undefined.","wrong":"import StatsWriterPlugin from 'webpack-stats-plugin';","symbol":"StatsWriterPlugin (ESM)","correct":"import { StatsWriterPlugin } from 'webpack-stats-plugin';"},{"note":"The package only exports StatsWriterPlugin; accessing it via a default require gives an object with the named export.","wrong":"const statsPlugin = require('webpack-stats-plugin');","symbol":"None","correct":"const { StatsWriterPlugin } = require('webpack-stats-plugin');"}],"quickstart":{"code":"const { StatsWriterPlugin } = require('webpack-stats-plugin');\n\nmodule.exports = {\n  // ... other config\n  plugins: [\n    new StatsWriterPlugin({\n      filename: 'stats.json',\n      fields: null, // include all fields\n      transform(data) {\n        return JSON.stringify(data, null, 2);\n      },\n    }),\n  ],\n};","lang":"javascript","description":"Basic webpack config that writes the full stats object to a file named 'stats.json' with formatting."},"warnings":[{"fix":"Set `fields: null` to include all stats fields, or provide an array of field names you need.","message":"The `fields` option defaults to `[\"assetsByChunkName\"]`, so by default not all stats properties are written.","severity":"gotcha","affected_versions":"*"},{"fix":"If using a function for `filename`, ensure it returns a string synchronously. For async filename generation, use the `transform` option.","message":"The `filename` can be a function returning a string, but the function receives the compilation data and must be synchronous.","severity":"gotcha","affected_versions":"*"},{"fix":"If you don't see the stats file, ensure you have `emit: true` (the default) or check that the webpack output path is correct.","message":"The plugin does not automatically emit the stats file in development mode or when `emit: false`. By default `emit: true`.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure `emit` is `true` (default) and that `filename` is within the output path. The plugin adds the file to the compiler's assets.","message":"When using webpack 5 with `output.clean: true`, the stats file may be deleted on rebuild if not emitted correctly.","severity":"gotcha","affected_versions":">=1.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev webpack-stats-plugin` and ensure it's in node_modules.","cause":"Package not installed or installed only as a dev dependency but not required correctly.","error":"Error: Cannot find module 'webpack-stats-plugin'"},{"fix":"Use `const { StatsWriterPlugin } = require('webpack-stats-plugin');` (named export) or `import { StatsWriterPlugin } from 'webpack-stats-plugin';` in ESM.","cause":"Wrong import syntax, likely using default import with CommonJS or incorrect require.","error":"TypeError: webpack_stats_plugin_1.StatsWriterPlugin is not a constructor"},{"fix":"Set `fields: null` to include all stats fields, or explicitly include needed fields like `['assets', 'chunks', 'modules']`.","cause":"The `fields` option restricts included fields; defaults to `[\"assetsByChunkName\"]`.","error":"Stats file is empty or missing expected fields"},{"fix":"Access `data` directly as the transformed JSON object; do not call `.toJson()` on it. For custom stats generation, use the `stats` option described above.","cause":"The transform function receives the raw stats object directly (not a compiler stats instance) in recent versions.","error":"TypeError: data.toJson is not a function","affected_versions":">=1.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}