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

No Parsed/Gziped sizes if there is build hash in output path #297

Open
martinkadlec0 opened this issue Jul 23, 2019 · 12 comments
Open

No Parsed/Gziped sizes if there is build hash in output path #297

martinkadlec0 opened this issue Jul 23, 2019 · 12 comments

Comments

@martinkadlec0
Copy link

martinkadlec0 commented Jul 23, 2019

Issue description

If there as build hash in webpack's output path, I get following error from WBA:
Error parsing bundle asset "/xxx/app/dist/[hash]/app.js": no such file.

My webpack output config:

	output: {
		filename: '[name].js',
		path: path.join(__dirname, './dist/[hash]/'),
		publicPath: `${cdnPublicPath}[hash]/`,
		chunkFilename: '[name].js',
	},

This causes that there is no gziped/parsed size on the WBA page.

Technical info

  • Webpack Bundle Analyzer version: 3.3.2
  • Webpack version: 4.35.0
  • Node.js version: 10.13
  • npm/yarn version: npm 6.9
  • OS: Mac OS Mojave

Debug info

How do you use this module? As CLI utility or as plugin?
Plugin

If plugin, what options were provided? (e.g. new BundleAnalyzerPlugin({ analyzerMode: 'disabled', generateStatsFile: true }))
No options

What other Webpack plugins were used?
webpack.DefinePlugin
CircularDependencyPlugin
FlowStatusWebpackPlugin
ExtractCssChunks
HtmlWebpackPlugin
SpriteLoaderPlugin

Demo repo

https://github.com/martinkadlec0/wba-build-hash

@valscion
Copy link
Member

Are you able to create a reproduction repository so that some contributor or us could check this error?

@martinkadlec0
Copy link
Author

Sure, there you go https://github.com/martinkadlec0/wba-build-hash

@valscion
Copy link
Member

Ah ok, now I get it! Thank you, the reproduction repository helped.

This does seem to be a lack of a feature that could also be categorized as a bug. The crux is this webpack config:

output: {
    filename: '[name].js',
    path: __dirname + '/dist/[hash]/',
  },

and that webpack-bundle-analyzer uses the path as-is instead of using some version where the [hash] would've been replaced with what it was in the end.

vesa_Vesas-MacBook-Pro____code_muut_webpack-bundle-analyzer_wba-build-hash__zsh_

vesa_Vesas-MacBook-Pro____code_muut_webpack-bundle-analyzer_wba-build-hash__zsh_

vesa_Vesas-MacBook-Pro____code_muut_webpack-bundle-analyzer_wba-build-hash__zsh_

vesa_Vesas-MacBook-Pro____code_muut_webpack-bundle-analyzer_wba-build-hash__zsh_

@valscion
Copy link
Member

So the problem is here:

default:
return this.compiler.outputPath;

The issue is not present when generating stats JSON separately and using the CLI to open the reporter:

npx_webpack-bundle-analyzer_dist_c549fb74e294621ca40f_stats_json__node_

Screenshot 2019-07-30 at 20 36 49

So we should figure out a way to get the bundle directory location from somewhere else than compiler.outputPath as that path has not been expanded by webpack. Hmm...

@valscion
Copy link
Member

Damn, the outputPath inside the Stats object (https://webpack.js.org/api/stats/#structure) is also not expanded but instead has the same /wba-build-hash/dist/[hash]/" end... I wonder if we'll need to replace [hash] with the hash we have in the Stats object.

The docs would indicate that [hash] is the only special replacement there, so it should not be too big a can of worms 😅 https://webpack.js.org/configuration/output/#outputpath

@valscion
Copy link
Member

valscion commented Jul 30, 2019

Ooh nice: webpack/webpack#1648

EDIT: Hmm, but I wonder if it's possible for us to use this functionality, given we don't depend on webpack directly.. hmm hmm

@valscion
Copy link
Member

I had time to create a proof of concept of fixing this issue in #304, but unfortunately I don't have more time right now to figure this out and I don't know when I would have time.

@martinkadlec0
Copy link
Author

Thanks a lot for looking into it 👍

@Sysix
Copy link

Sysix commented Jun 10, 2021

Update on this issue?
I got the same problem wen using output: {..., chunkFilename: '[name].js?id=[chunkhash]' }

@valscion
Copy link
Member

No updates

@Sysix
Copy link

Sysix commented Jun 10, 2021

I found out that loader-utils has a function to maybe resolve this problem: interpolateName
https://github.com/webpack/loader-utils#interpolatename

Sadly I'm not the pro webpack user, who can find the right line to edit.

@valscion
Copy link
Member

This is the PR that I got started on that made some progress, but then got a bit stuck and uncertain if I was heading in the right direction: #304

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

Successfully merging a pull request may close this issue.

3 participants