Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add "name" field to package.json to Resolve Webpack chunk loading conflicts #481

Merged

Conversation

PierreMigani
Copy link

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 the sonata-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 option output.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 the name field from package.json.
webpack option reference: https://webpack.js.org/configuration/output/#outputuniquename

However, we noticed that our package.json did not define the name field, and neither did the package.json from sonata-project/form-extensions. To temporarily resolve this issue, we added a name to our package.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 the package.json. This change would help ensure that webpack generates a unique name for all its globals.

Changelog

### Added
- `name` field to `package.json`, avoiding webpack globals conflicts issues with other webpack projects

…y adding missing "name" field to package.json
Copy link

@lowwa132 lowwa132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves the issue described, on my project

@VincentLanglet
Copy link
Member

Resolves the issue described, on my project

Thanks for the feedback ; a beer when you want ;)

@VincentLanglet VincentLanglet merged commit ae0dfe2 into sonata-project:2.x Apr 13, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants