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.

assetModuleFilename doesn't affect chunkhash of final javascript file

See original GitHub issue

Bug report

What is the current behavior? Changing assetModuleFilename in configuration doesn’t change chunkhash of files using imported images. this can lead to various caching problems (browser, procies, cdn etc)

If the current behavior is a bug, please provide the steps to reproduce.

you can find an example here https://github.com/stuff/webpack-assets-bug

webpack config:

{
  mode: 'development',
  entry: './src/index.js',
  output: {
    filename: '[name].[chunkhash].js',
    path: path.resolve(__dirname, 'dist'),
    assetModuleFilename: 'img/[name]-[hash][ext]',
  },
  module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/i,
        type: 'asset/resource',
      },
    ],
  },
}

both assetModuleFilename: 'img/[name]-[hash][ext]' and assetModuleFilename: 'assets/[name]-[hash][ext]' results in a js file named main.09783b82d14c2e26304e.js actually resulting in 2 differents files with:

eval("module.exports = __webpack_require__.p + \"img/oc-c1f902d15bfedbcc2538.png\"
eval("module.exports = __webpack_require__.p + \"assets/oc-c1f902d15bfedbcc2538.png\";

What is the expected behavior?

I would expect that the final js filename has a different chunkhash

Other relevant information: webpack version: 5.64.4 Node.js version: v16.13.0 Operating System: ubuntu 20.04

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vankopcommented, Nov 26, 2021

@alexander-akait I think you did not get what @stuff is expecting… It is ok that asset has same hash. it is not ok that js chunk that uses this asset has same hash. (pls note asset name are different img/ vs asset/ prefix)

0reactions
stuffcommented, Nov 26, 2021

exactly this 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Compilation Hash for asset/resource files in Webpack 5
The chunk file names all get the same and correct compilation hash. For example, the main bundle files are all correct: appbundle.
Read more >
Output - webpack
Note this option does not affect output files for on-demand-loaded chunks. It only affects output files that are initially loaded. For on-demand-loaded chunk ......
Read more >
Adding Hashes to Filenames - SurviveJS
If the file contents related to a chunk are different, the hash changes as well, thus the cache gets invalidated. More accurately, the...
Read more >
webpack-cli - npm
webpack CLI provides a flexible set of commands for developers to increase speed when setting up a custom webpack project. As of webpack...
Read more >
webpack - Fig.io
Update the version when config changed in a way which doesn't allow to reuse cache. ... --experiments-output-module, Allow output javascript files as module ......
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