Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack info and warning messages make the stats.json invalid #280

Closed
gex opened this issue May 8, 2019 · 2 comments
Closed

webpack info and warning messages make the stats.json invalid #280

gex opened this issue May 8, 2019 · 2 comments

Comments

@gex
Copy link

gex commented May 8, 2019

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
@valscion
Copy link
Member

valscion commented May 8, 2019

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 {.

@valscion valscion closed this as completed May 8, 2019
@gex
Copy link
Author

gex commented May 8, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants