Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Chunk names do not respect filename setting if filename is a function #7085

Closed
skylerberg opened this issue Oct 20, 2023 · 1 comment · Fixed by #7335
Closed

Chunk names do not respect filename setting if filename is a function #7085

skylerberg opened this issue Oct 20, 2023 · 1 comment · Fixed by #7335
Assignees

Comments

@skylerberg
Copy link

Bug report

What is the current behavior?

Chunks will receive names containing a hash with this code:

output: {
      filename: '[name]-[contenthash].js',
}

Chunks will receive names without hashes (e.g., 113.js) with this code:

output: {
      filename: () => '[name]-[contenthash].js',
}

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

Here is a full minimal reproduction of the issue: https://github.com/skylerberg/webpack-chunk-name-issue

You can observe the behavior by downloading the repo and running:

$ npm install
$ npm run build
$ ls dist

You will see a chunk without a hash in its name.

What is the expected behavior?

I would expect identical behavior between the two examples above because the function version always resolves to the same string as the original snippet.

Other relevant information:
webpack version: 5.89.0
Node.js version: v18.17.1
Operating System: Pop!_OS 20.04

It is possible to workaround this bug by explicitly setting chunkFilename. So I'm fine, but I wanted to report this so that it can get fixed and others won't be impacted by this surprising behavior.

@alexander-akait
Copy link
Member

I want to say it is not a bug, there is our logic https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L835, we can't run the funtion before getting the name because we pass pathData to this function (https://webpack.js.org/configuration/output/#outputfilename), I want to say it is a limitation and we should improve our docs here

@alexander-akait alexander-akait transferred this issue from webpack/webpack Dec 28, 2023
@snitin315 snitin315 self-assigned this Jun 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants