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

Fail to analyze webpack 5 stats.json due to hidden assets #385

Closed
ZKHelloworld opened this issue Oct 12, 2020 · 4 comments
Closed

Fail to analyze webpack 5 stats.json due to hidden assets #385

ZKHelloworld opened this issue Oct 12, 2020 · 4 comments

Comments

@ZKHelloworld
Copy link
Contributor

Issue description

We recently switch webpack to version 5 and webpack-bundle-analyzer fail to analyze.
The error below is logged:
image

Debug info

We dive into code and find out the error is produced by this line of code:
image
It turns out that webpack version 5 generates a new kind of assets without a name:
image

We temporary fix this by checking whether name is existed or not:
image

@th0r
Copy link
Collaborator

th0r commented Oct 12, 2020

Could you create a PR?

@ZKHelloworld
Copy link
Contributor Author

@th0r
Sure.
I shall take some time to investigate what does hidden assets means first.

@ZKHelloworld
Copy link
Contributor Author

It seems like webpack 5 change the schema of assets[*] and add a new attribute type here
image
More types are added here

In our case, we config the stats.excludeAssets as:
image
The stats.json contains the hidden assets result:
image
Comment out the stats.excludeAssets, no hidden assets is generated.

It seems like webpack 5 generate more information in stats.json.


Probably a better fix is to check whether the type is asset or not:

  // Picking only `*.js or *.mjs` assets from bundle that has non-empty `chunks` array
  bundleStats.assets = _.filter(bundleStats.assets, asset => {
    // Filter out non 'asset' type asset if type is provided (Webpack 5 add a type to indicate asset types)
    if (asset.type && asset.type !== 'asset') {
      return false;
    }

    // Removing query part from filename (yes, somebody uses it for some reason and Webpack supports it)
    // See #22
    asset.name = asset.name.replace(FILENAME_QUERY_REGEXP, '');

    return FILENAME_EXTENSIONS.test(asset.name) && !_.isEmpty(asset.chunks) && isAssetIncluded(asset.name);
  });

@th0r
Copy link
Collaborator

th0r commented Nov 8, 2020

Fixed in #386

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