webpack-contrib / webpack-bundle-analyzer

Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
MIT License
12.58k stars 487 forks source link

Analyzer getting parsing errors after upgrade to Webpack 5 for edge cases #409

Open hasan-wajahat opened 3 years ago

hasan-wajahat commented 3 years ago

Issue description

I had been easily creating analyzer reports with my very old configuration of laravel-mix 2 (running webpack 2 underneath). Finally I have managed to upgrade our config to laravel mix 6 (running webpack 5). Webpack is correctly creating all my bundles and webpack-bundle-analyzer even creates a proper report for this configuration. But the anazlyer is also throwing the following errors:

Error parsing bundle asset "/Users/hasan/Web_Projects/idf/IDF-web/public/js/components/payment/checkoutForm.js": Cannot read property 'arguments' of undefined
Error parsing bundle asset "/Users/hasan/Web_Projects/idf/IDF-web/public/js/pages/designLeague/coach_panel.js": Cannot read property 'arguments' of undefined
Error parsing bundle asset "/Users/hasan/Web_Projects/idf/IDF-web/public/js/pages/designLeague/member_panel.js": Cannot read property 'arguments' of undefined
Error parsing bundle asset "/Users/hasan/Web_Projects/idf/IDF-web/public/js/pages/paymentMethods/create.js": Cannot read property 'arguments' of undefined
Error parsing bundle asset "/Users/hasan/Web_Projects/idf/IDF-web/public/js/pages/members/studentProfile.js": Cannot read property '0' of undefined

Sadly I don't get any more errors that would give me a clue why bundle is failing.

I think my issue is similar to problems mentioned in #327

Technical info

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 940.84 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
    Yarn: 1.22.10 - ~/.yarn/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  npmPackages:
    brotli-webpack-plugin: ^1.1.0 => 1.1.0 
    browser-sync-webpack-plugin: ^2.3.0 => 2.3.0 
    webpack-bundle-analyzer: ^4.3.0 => 4.3.0 

Debug info

I am using it as a plugin and here is how I run it:

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
  plugins: [
           new BundleAnalyzerPlugin({
                analyzerMode: 'static',
                reportFilename: `${path.resolve(__dirname, 'public/storage/bundle-analyzer')}/app-${DOTENV.APP_VERSION}.html`,
                openAnalyzer: false,
            }),
  ]
}

What other Webpack plugins were used? I am not explicitly using any more plugins but laravel mix under the hood is using plugins for minification and versioning etc..

The stats file is attached below. Also no exception was thrown while creation of the stats file based on your recommended method (with analyzer disabled and source: false).

stats.json.zip

hasan-wajahat commented 3 years ago

So just wanted to share that the I am no longer seeing this error after I started using optimization.runtimeChunk. Now my config is like this for optimization:

optimization: {
        runtimeChunk: {
            name: 'js/runtime'
        },
        splitChunks: {
            cacheGroups: {
                vendor: {
                    test: /[\\/]node_modules[\\/](jquery|foundation-sites|foundation-datepicker|intersection-observer)[\\/]/,
                    name: 'js/vendor',
                    chunks: 'all',
                },
            },
        },
    }

I don't know if this issue should be closed based on this or whether bundle should work even if no special runtime file is created. Also a point to note is that I needed an explicit runtime file because I have multiple entry point js files for single pages in my app.