question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using `[name].[contenthash].css` for `filename` is not deterministic

See original GitHub issue
  • Operating System: macOS BigSur 11.1
  • Node Version: 12.18.2
  • NPM Version: 7.5.2
  • webpack Version: 5.22.0
  • mini-css-extract-plugin Version: 1.3.7

Expected Behavior

contentHash to be stable and deterministic

Actual Behavior

Building same project without making changes between build will “randomly” result in different contentHash sometimes

Code

I don’t have minimal reproduction, but I did bit of a code dive so hopefully following explanation could replace reproduction setup.

In https://github.com/webpack-contrib/mini-css-extract-plugin/blob/6009bd27374bbc10530a2dbeed2f6c54bcfb8da1/src/index.js#L532-L556 for webpack@5 chunkGraph is used. chunkGraph.getChunkModulesIterableBySourceType(chunk, MODULE_TYPE); return SortedSet of modules, however they are actually not sorted. Per https://github.com/webpack/webpack/blob/911ec1aa67011e25aa1449610f5b0b557edd5459/test/SortableSet.unittest.js it seems SortedSet means that it exposes .sort() method to get the Set sorted.

Later on m.updateHash(hash, { chunkGraph }); is called in order of modules in the SortedSet (which actually isn’t sorted, and order of modules actually seem that can change between builds). Finally this result in contentHash that is generated not to be stable/deterministic.

For part about getChunkModulesIterableBySourceType returning unsorted modules I find minor mention in https://github.com/webpack/webpack/projects/6 :

Should getChunkModulesIterableBySourceType be sorted in general?

And following code for that method ( https://github.com/webpack/webpack/blob/05768d9029b9024d9a8d5f1aa56e649d9b963f57/lib/ChunkGraph.js#L538-L549 for entry), we can see that SortedSet is used (in modulesBySourceType implementation), but .sort() or .sortWith() is not called on it resulting in preserving order of module creation (?) which itself is probably not deterministic due to lot of async execution.

How Do We Reproduce?

As mentioned above - I don’t have minimal reproduction for this problem, but I hope my research and description explain the issue well?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sokracommented, Feb 17, 2021

Yes identifier is a good choice. There are a few comparators in webpack.utils.comparators that you can/should use.

1reaction
alexander-akaitcommented, Feb 17, 2021

@pieh We will fix it today (I think), I think https://github.com/webpack-contrib/mini-css-extract-plugin/issues/454 can be related, I will check it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Non-deterministic contenthash generation · Issue #512 - GitHub
We have very recently encountered an issue where this process has resulted in packs with different contenthash fingerprints in their filename.
Read more >
Adding Hashes to Filenames - SurviveJS
Even though the generated build works, the file names it uses is problematic. It doesn't allow to leverage client level cache efficiently as...
Read more >
Webpack config for better monitoring - RelativeCI
Adding the content hash suffix to file names helps browsers cache the assets and only request the asset from the server when the...
Read more >
Webpack - Inconsistent contenthash between DevServer and ...
I have a script that launches WebpackDevServer & Puppeteer to create SSR files (HTML) for my site, and at the same time generate...
Read more >
How to setup a vue project with webpack. - DEV Community ‍ ‍
as params to the MiniCssExtractPlugin. To hash our files we need to add. name: "[name][contenthash:8].[ext]",. to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found