[contenthash] doesn't match between the assets in hooks and emitted output

Author: psimkCreated Apr 20, 2021Updated Jan 2, 2026

Current behaviour

When using the assetTags from the callback of alterAssetTags or alterAssetTagGroups hooks (didn't test other hooks), the contenthash portion of the asset filename differs from the contenthash of the same asset in the emitted output.

For example:

given filename: "bundle.[contenthash].js"

In alterAssetTags hook, assetTags.scripts[0].attributes.src evaluates to: bundle.1817f49c37ed2ca083b2.js

whereas in the final output and also the emitted index.html it is: bundle.2e55dea7e3e197f9902d.js

Expected behaviour ☀️

The content hashes in the hooks filename and in the emitted output should be the same.

Reproduction Example

https://github.com/psimk/html-plugin-contenthash-reproducible

Environment

  • Node.js v14.16.0
  • OS: linux 5.4.0-72-generic
  • NPM 6.14.11
  • Webpack 5.34.0
  • HTMLWebpackPlugin 5.3.1

Source: jantimon/html-webpack-plugin