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

PeerDependencies are not passed through to remote if shell is not using it #731

Open
2 tasks
Kawachen97 opened this issue Jan 14, 2025 · 3 comments
Open
2 tasks
Labels
status:reproducible-stackblitz-requested We require a reproducible stackblitz.

Comments

@Kawachen97
Copy link

With what library do you have an issue?

native-federation

Reproduction of the bug/regression with instructions

Hey,
we are using a package that needs some peerDependencies to work properly. Our shell is not using the components that need the peerDependency. We don't know which of those peerDepenencies will be needed by the remote and therefor also don't know which of them to install. We also want to prevent installing and sharing all of them. On startup, native-federation fails, while resolving the dependencies, which are declared as peer:
image (13)
As a workaround we are now skipping those subpackages in the federation.config:
image (14)

Expected behavior

My expectation would be, that those peerDependency constraints are passed through to the remote.
If the remote needs them, it can install them and if not, then not.

Versions of Native/Module Federation, Angular, Node, Browser, and operating system

NativeFederation: 18
Angular: 18

Other information

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@manfredsteyer
Copy link
Contributor

manfredsteyer commented Jan 17, 2025

Hi @Kawachen97,

Yes, ngx-charts should be shared automatically, regardless of whether it's used in the host or not.

Is it possible that ngx-charts is not a peer dependency but an ordinary dependency of @escid-ux/angular-components?

If it's an ordinary dependency, the new transient flag could help:
https://github.com/angular-architects/module-federation-plugin/blob/main/libs/native-federation/docs/share-faq.md#transitive-dependencies

You can activate it for all deps (using shareAll) or for specific deps (using share).

@Kawachen97
Copy link
Author

Hi @manfredsteyer,

I'm sorry, I don't think I expressed my thoughts well. After discussing it with a colleague, I want to try again:

The @escid-ux/angular-components is a package for sharing a collection of separate components (classic components lib). In our shell/host frontend and in our remote frontend we use this package. So I thought it might make sense to share it.

One of the components inside the @escid-ux/angular-components is dependent on ngx-charts (@escid-ux/angular-components/organisms/charts in particular). ngx-charts is definitely referenced as a peerDependency, so if we want to use it, we need to make sure in the shell/host that ngx-charts is installed. In our shell/host, we don't use this particular component, so we don't have ngx-charts installed. When we now share the @escid-ux/angular-components/organisms/charts component via native federation, the component's javascript file is checked and fails because ngx-charts obviously cannot be found. If we don't share it, everything works as expected.

I now understand that this behaviour is quite normal because native federation has to go through the shared packages to make sure everything is available. At first I was under the impression that we didn't need the peerDependency to be available at compile time and that it would be enough to have ngx-charts installed on the remote frontend and fetch it at runtime. Is this true?

Now that I think about it, it probably doesn't even make sense to share @escid-ux/angular-components/organisms/charts, because it is only used by the remote, and only share what is really used in both shell/host and remote.

@manfredsteyer
Copy link
Contributor

It should indeed be enough to have this dependency in the remote(s).

Can you please provide a minimal reproduction of this issue via a github project?

@manfredsteyer manfredsteyer added status:reproducible-stackblitz-requested We require a reproducible stackblitz. and removed status:needs-work labels Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:reproducible-stackblitz-requested We require a reproducible stackblitz.
Projects
None yet
Development

No branches or pull requests

2 participants