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

Do not wrap duplicated assets when they are in different targets #9348

Merged
merged 1 commit into from Oct 29, 2023

Conversation

devongovett
Copy link
Member

This fixes a regression from #9109. When an asset is duplicated, that PR caused it to be wrapped so it gets deduplicated at runtime. However, if the duplication occurs in separate targets, this is not necessary. It resulted in parcelRequire getting added to library builds, causing downstream errors in poorly written bundlers trying to detect CJS usage (vercel/next.js#57649) (and also unnecessary global variables). The fix is to detect whether the duplication occurs within the same target.

// If the asset is available in multiple bundles in the same target, it's referenced.
if (
this.getBundlesWithAsset(asset).filter(
b => b.target.distDir === bundle.target.distDir,
Copy link
Member Author

Choose a reason for hiding this comment

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

we should probably have a target.id at some point, but this is how the default bundler does it already.

@devongovett devongovett merged commit c45c296 into v2 Oct 29, 2023
15 of 16 checks passed
@devongovett devongovett deleted the fix-wrap-multi-target branch October 29, 2023 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants