Add "name" field to package.json to Resolve Webpack chunk loading conflicts #481
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Subject
Hello,
I'd like to suggest a small change to the project, that might avoid issues for users also using webpack for asset management.
Issue Description
I'm a contributor to a Symfony project that uses Sonata for our admin interface.
In our project, when updating our outdated
sonata-project/form-extensions
Composer package, we encountered a conflict between our webpack runtime and thesonata-project/form-extensions
runtime.This conflict happens because both try to use the same global JavaScript variable,
globalThis.webpackChunk
, to load chunks. The name of this variable is defined by the Webpack optionoutput.chunkLoadingGlobal
.webpack option reference: https://webpack.js.org/configuration/output/#outputchunkloadingglobal
This issue made our chunks load twice, causing our JavaScript to run twice, which led to unexpected problems.
Research and Temporary Solution
When we looked into the problem, we found out that webpack 5 solves it by automatically giving unique names to its global variables with the
output.uniqueName
option, which per default uses thename
field frompackage.json
.webpack option reference: https://webpack.js.org/configuration/output/#outputuniquename
However, we noticed that our
package.json
did not define thename
field, and neither did thepackage.json
fromsonata-project/form-extensions
. To temporarily resolve this issue, we added aname
to ourpackage.json
, which successfully mitigated the conflict.Feature Request
To prevent similar conflicts in the future with webpack-managed projects, I suggest adding a
name
field to thepackage.json
. This change would help ensure that webpack generates a unique name for all its globals.Changelog