Webpack-bundle-analyzer: webpack info and warning messages make the stats.json invalid

Created on 8 May 2019  ·  2Comments  ·  Source: webpack-contrib/webpack-bundle-analyzer

Issue description

after running the webpack --profile --json > dist/stats.json command the cli tool (webpack-bundle-analyzer dist/stats.json) throws an error:

Couldn't read webpack bundle stats from "[...]/dist/stats.json":
SyntaxError: Unexpected token [...] in JSON at position 0

the first 2 rows of the stats.json:

Webpack is in undefined mode.
warning: couldn't find native brotli support in zlib library. trying to fall back to iltorb.

first is a webpack warning because i didn't set the mode, the second is a warning from the brotli-webpack-plugin.

in my opinion having webpack info and warning messages are not uncommon so it would be great to find another way to save the stats.json instead of redirecting the output stream.

Technical info

  • Webpack Bundle Analyzer version: 3.3.2
  • Webpack version: 4.30.0
  • Node.js version: 10.15.3
  • npm/yarn version: 1.15.2
  • OS: macOS Mojave 10.14.4

Debug info

How do you use this module? As CLI utility or as plugin?

CLI: webpack-bundle-analyzer dist/stats.json

What other Webpack plugins were used?

  • html-webpack-plugin
  • compression-webpack-plugin
  • brotli-webpack-plugin

Most helpful comment

thanks for looking into this!

it turned out the first message is my fault, i left a console.log in the webpack.config.js. 🤦‍♂️ the other is an issue with the brotli-webpack-plugin.

All 2 comments

There's the option of using this library as a plugin and supply generateStatsFile option to it.

The issue with:

Webpack is in undefined mode.
warning: couldn't find native brotli support in zlib library. trying to fall back to iltorb.

cannot be fixed by us, as it is some other tool that is outputting warnings into your standard output. The > character redirects all standard output to a file of your choosing.

With the --json flag, webpack should only output valid JSON — one that doesn't contain anything before the opening curly brace {.

thanks for looking into this!

it turned out the first message is my fault, i left a console.log in the webpack.config.js. 🤦‍♂️ the other is an issue with the brotli-webpack-plugin.

Was this page helpful?
0 / 5 - 0 ratings