admin管理员组文章数量:1301562
I recently migrated and split my Angular 17 frontend application into several micro-frontends using Webpack Module Federation. My goal was to enable independent deployment of each micro-frontend (each representing a distinct business area) to gain better control over production deployments.
Each micro-frontend is entirely separate, with no communication or shared dependencies between them, except for a shared Angular components library called @common-frontend
.
Current Setup
The @common-frontend
library is the only shared dependency between the micro-frontends. To allow independent deployment of each micro-frontend, I configured @common-frontend
as follows in the shared
section:
shared: {
"@common-frontend": { singleton: false, strictVersion: false },
}
This setup ensures that each micro-frontend can use its own version of @common-frontend
without conflicts. So far, everything worked fine!
The Issue
Recently, I added custom Angular Material form controls to the @common-frontend
library. These controls are used like this:
<mat-form-field appearance="outline">
<mat-label>Name</mat-label>
<lib-custom-input placeholder="name" formControlName="name" />
</mat-form-field>
Here’s where the problem arises. To make it easier to explain, let’s assume three Angular 17 applications:
- A (host)
- B and C (remotes)
Scenario 1: Different Versions of @common-frontend
If B and C have different versions of @common-frontend
, everything works perfectly. When navigating between B and C, the appropriate chunks for @common-frontend
are fetched and loaded dynamically based on the respective app's version.
Scenario 2: Same Version of @common-frontend
If B and C share the same version of @common-frontend
, the first app I navigate to (e.g., B) fetches the chunk for @common-frontend
. However, when I then navigate to C, Webpack does not fetch the chunk again since it is already cached. This results in the following error when trying to use the custom Angular Material form controls:
Error: mat-form-field must contain a MatFormFieldControl.
This issue currently occurs only with
mat-form-field
. All other components from@common-frontend
work correctly, even when the same version is used across multiple micro-frontends.
I believe this issue stems from Angular’s injection context not being properly shared or initialized between micro-frontends. Refreshing the page resolves the issue, but this is not an acceptable solution for production.
Goals
Here are my goals:
- Maintain one Angular application per "business" domain.
- Enable independent deployment of each micro-frontend without causing side effects on other applications.
- Use a shared components library (
@common-frontend
) across all micro-frontends.
Questions and Concerns
- Could this issue be related to how I’m using Webpack Module Federation?
- Is there a better or smarter way to achieve my goals while avoiding such injection issues?
- Are there specific considerations or patterns I should follow when sharing Angular libraries between micro-frontends?
If anyone has faced similar issues or has insights into resolving this problem, I would greatly appreciate your help.
版权声明:本文标题:Webpack Module Federation and shared Angular Library issue with custom MatFormFieldControl - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738511958a2090863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论