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.
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?
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.
Most helpful comment
thanks for looking into this!
it turned out the first message is my fault, i left a
console.login thewebpack.config.js. 🤦♂️ the other is an issue with thebrotli-webpack-plugin.