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

fix(module-federation): collect secondary entry points from exports #26878 #27999

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

Coly010
Copy link
Contributor

@Coly010 Coly010 commented Sep 19, 2024

Current Behavior

Some packages that use exports in the package.json may point to a directory such as esm/<entrypoint>.
They would still be imported such as mypackage/secondary-point.
This needs to be shared still for Module Federation.

However, our current logic for finding secondary entry points for packages looks at the sub dirs of the package and tries to match it with the exports fiels.

Therefore if mypackage/secondary-point was set up such that

"./secondary-point": {
  default: "esm/secondary-point/index.mjs"
}

then it would never be found correctly, causing share problems.

Expected Behavior

exports of secondary entrypoints should be shared correctly

Related Issue(s)

Fixes #26878

@Coly010 Coly010 requested a review from jaysoo as a code owner September 19, 2024 15:54
@Coly010 Coly010 self-assigned this Sep 19, 2024
Copy link

vercel bot commented Sep 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Sep 19, 2024 5:26pm

@Coly010 Coly010 force-pushed the module-federation/collect-exports branch from 4baffff to 1f8c66b Compare September 19, 2024 16:08
@Coly010 Coly010 enabled auto-merge (squash) September 19, 2024 17:23
@Coly010 Coly010 force-pushed the module-federation/collect-exports branch from 1f8c66b to ab2052e Compare September 19, 2024 17:23
@Coly010 Coly010 merged commit f767bab into master Sep 19, 2024
6 checks passed
@Coly010 Coly010 deleted the module-federation/collect-exports branch September 19, 2024 17:58
@goldsam
Copy link

goldsam commented Sep 20, 2024

@Coly010 Thank you for addressing this! I was able to drastically simplify my config.

}[]
): void {
for (const [relativeEntryPoint, exportOptions] of Object.entries(exports)) {
if (exportOptions?.['default']?.search(/\.(js|mjs|cjs)$/)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Coly010 This causes the following error in some cases because for whatever reason search is not a function and it does not handle that gracefully.

 NX   exportOptions?.default?.search is not a function

Can we update this to the following to have a bit more safety around this and prevent that error?

Suggested change
if (exportOptions?.['default']?.search(/\.(js|mjs|cjs)$/)) {
if (exportOptions?.['default']?.search?.(/\.(js|mjs|cjs)$/)) {

@rathpc
Copy link
Contributor

rathpc commented Sep 26, 2024

@Coly010 I created an issue for the problem mentioned above #28139

Copy link

github-actions bot commented Oct 3, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nx + Module federation + Angular gives error NG0912 when using ng-zorro-antd
4 participants