webpack-contrib / webpack-bundle-analyzer

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

Incorrect bundle paths when bundles are in multiple directories. #506

Open Undistraction opened 2 years ago

Undistraction commented 2 years ago

Issue description

Where bundles are output to more than one directory, bundle paths are incorrect.

I'm using webpack-bundle-analyser with Gatsby via gatsby-plugin-webpack-bundle-analyser-v2 which is a very thin plugin. Gatsby adds bundles to /public/, however another plugin I use gatsby-plugin-netlify-cms adds bundles to /public/admin/. When BundleAnalyzerPlugin derives the bundleDir it resolves (using this.compiler.outputPath to /path/to/public/admin/ which it then uses as a prefix for all bundle paths. This means only the bundles that are generated to /admin/ are correct. The rest are not and result in warnings:

Error parsing bundle asset "/Users/me/Sites/www/public/app.js": no such file

It seems the current architecture can't handle situations where bundles are in written to different locations.

Technical info

  System:
    OS: macOS 12.3.1
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 133.81 MB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.2/bin/npm
    Watchman: 2021.11.15.00 - /usr/local/bin/watchman
  npmPackages:
    gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.26 => 1.1.26 

valscion commented 2 years ago

Hmm this does sound complicated and a likely bug. Would you be able to create a small reproduction so it would be possible to fix this at some point?

pionl commented 2 years ago

Hi, I can confirm this.

Here a part of json I have:

"children": [{
        "hash": "acbf87df4bf149c73cd1",
        "version": "5.65.0",
        "time": 28955,
        "builtAt": 1652089618297,
        "publicPath": "/assets/static/",
        "outputPath": "/app/public/assets/static",
        "assetsByChunkName": {
            "static:fonts": ["style/fonts-acbf87df4bf149c73cd1.css", "js/fonts-0a26b8e32bf029c9d244c1cd344336a5.js"],
            "static:pdf-availability": ["style/pdf-availability-acbf87df4bf149c73cd1.css", "js/pdf-availability-6a5493c1496fd7e44b08a976c90cd01a.js"],
            "static:pdf": ["style/pdf-acbf87df4bf149c73cd1.css", "js/pdf-801d6111f8a308117ba0f8c07cc16d37.js"]
        },

Warning for the file:

Error parsing bundle asset "/app/public/assets/js/pdf-availability-6a5493c1496fd7e44b08a976c90cd01a.js": no such file

It seems it ignores the publicPath ?

valscion commented 2 years ago

Please create a small reproduction case

pionl commented 2 years ago

I'l try 👍 Thank you for your time