Giter Club home page Giter Club logo

Comments (19)

balanceiskey avatar balanceiskey commented on May 9, 2024

Not sure if it helps, but we get the same error when running the CLI tool against a stats.json file as well. Managed to get it running by disabling the DedupePlugin.

from webpack-bundle-analyzer.

alexindigo avatar alexindigo commented on May 9, 2024

Same here. And disabling Dedupe plugin helped as well. Although it won't be the same as real bundle in my understanding.

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

@Diokuz do you use Dedupe plugin for your production build as well?

from webpack-bundle-analyzer.

alexindigo avatar alexindigo commented on May 9, 2024

@th0r and I tried to run production build with minification, but analyzer still shows unminified sizes (in megabytes).

from webpack-bundle-analyzer.

kishorevarma avatar kishorevarma commented on May 9, 2024

I did some research on this bug, I am using code splitting in my project , so I have the chunk files those are loaded using webpackJsonp , following code is used to calculate the size of those generated assets

if (_.get(node, 'callee.name') === 'webpackJsonp') {
  state.sizes = getModulesSizesFromFunctionArgument(args[1]);
   return;
}

function getModulesSizesFromFunctionArgument(arg) {
  if (arg.type === 'ObjectExpression') {
    const modulesNodes = arg.properties;

    return _.transform(modulesNodes, (result, moduleNode) => {
      const moduleId = moduleNode.key.name || moduleNode.key.value;
      const moduleBody = moduleNode.value.body;

      result[moduleId] = moduleBody.end - moduleBody.start;
    }, {});
  }

  if (arg.type === 'ArrayExpression') {
    const modulesNodes = arg.elements;

    return _.transform(modulesNodes, (result, moduleNode, i) => {
      if (!moduleNode) return;

      result[i] = moduleNode.body.end - moduleNode.body.start;
    }, {});
  }

  return {};
}

Problem exist in these two lines, which are pre assuming all the node types are function expressions, but there can be Array Nodes or Literal Nodes for those there wont be any body in AST

result[moduleId] = moduleBody.end - moduleBody.start;
result[i] = moduleNode.body.end - moduleNode.body.start;

@th0r above thing might be helpful to fix. this issue can be reproduced if all the asset files exist in the bundle directory.

Cheers

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

@kishorevarma thanks! Thats exactly what I was thinking of.

but there can be Array Nodes or Literal Nodes

Do you know in which situations they can be arrays or literals?

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

@Diokuz @alexindigo @balanceiskey
Can someone of you guys send me archive with broken bundle? Everything that webpack has created + stats file.

from webpack-bundle-analyzer.

Diokuz avatar Diokuz commented on May 9, 2024

@th0r yes, we are using new webpack.optimize.DedupePlugin(). Analyzer started to work when I disabled DedupePlugin.

Can someone of you guys send me archive with broken bundle? Everything that webpack has created + stats file.

Sorry, I cannot do this, our project is not open source ((

from webpack-bundle-analyzer.

PhiLhoSoft avatar PhiLhoSoft commented on May 9, 2024

I had the same issue, and the culprit was indeed webpack.optimize.DedupePlugin.
Note that I have the error when running webpack --profile --json which, if I understood correctly, is unrelated to this tool, actually.
Ah, now that I updated Webpack from 1.12.13 to 1.13.3, I no longer have the issue.
Funnily, when I removed the dedupe plugin for tests, I observed the same size of files generated in production. Looks like it is no longer necessary, at least with NPM 3, I guess.

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

So, appears that if one module is duplicate of another (has the same content) DedupePlugin replaces it's content with just module id in output bundle.

But seems like there is another case when module can be an object.

@sokra Could you explain this case please?

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

Released v1.4.1 with partial support for DedupePlugin (simple case with duplicated module ids).
Can you check it guys?

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

@Diokuz @PhiLhoSoft @alexindigo @balanceiskey
Could you check if v1.4.1 solves a problem?

from webpack-bundle-analyzer.

PhiLhoSoft avatar PhiLhoSoft commented on May 9, 2024

Alas, as said, since I upgraded my libraries and tools, I can no longer reproduce the issue (which is already a good thing, no?).

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

@PhiLhoSoft I thought you had to remove DedupePlugin from config?

from webpack-bundle-analyzer.

kishorevarma avatar kishorevarma commented on May 9, 2024

@th0r its fixed my issue, having array expression in assets files.

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

having array expression in assets files

Do you mean array in place of module wrapper?

from webpack-bundle-analyzer.

kishorevarma avatar kishorevarma commented on May 9, 2024

yeah exactly, following solved my issue :) thanks for that

function getModuleSize(node) {
  if (node.type === 'FunctionExpression') {
    return node.body.end - node.body.start;
  }

  if (node.type === 'Literal') {
    return node.end - node.start;
  }

  // Fallback for unknown node types
  return 0;
}

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

But seems like there is another case when module can be an object.

@TheLarkInn Need your help here, man)

from webpack-bundle-analyzer.

th0r avatar th0r commented on May 9, 2024

Released v1.5.2 with full DedupePlugin support (at least hope so 😜)

from webpack-bundle-analyzer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.