Closed pacoita closed 1 year ago
After further debugging, we found the root of the issue. In our pipeline, we set a new version in the package.json
when a new build is done (either a build all or just a single mfe).
Below is the logic to create a new version through our pipeline:
string currentVersion = sh(script: "npm run version --silent", returnStdout: true).trim()
packageJson = '{
"name": "b2b-frontend-MFE-TOKEN",
"version": "VERSION-TOKEN",
"repository": { "type": "git", "url": "https://...git" },
"publishConfig": { "registry": “…” },
"main": "",
"files": [ "dist", "nginx.conf", "mime.types" ]}'.replace("MFE-TOKEN", mfe).replace("VERSION-TOKEN", currentVersion)
writeFile file: "dist/apps/${mfe}/package.json", text: packageJson
Looking at the bundles, we saw that our monorepo shared library (b2b-mfe-shared
) was taking the latest build version, even if the shared lib did not change:
This was creating a new instance of the service if we were building just one mfe, since a new version was created and this was used as a reference for the shared library in the affected (newly built) mfe:
As a temporary solution, we stopped updating the version in the package.json.
However, is this a known and wished behavior? This way, it seems we are binding the mfes to a specific version
As discussed, the version found in the monorepo's package.json is used.
Our Setup We have some
Angular 14.x
applications in aNX Monorepo
using@angular-architects/module-federation": "^14.3.0"
. We have a shared library added to thesharedMappings
array, as we want to share it across all mfes. This shared library exports some services, e.g.LoginService
, where the shell app sets the user data and the different remote mfes read it.Current Issue When we deploy all mfes together, everything works fine. But if we build one mfe individually and deploy only this one to leverage the mfes architecture, we notice that a new bundle is created for the shared library and added to the newly built mfe (this is not the case when we make a build all). This breaks our logic, as a new service instance is created without the user data set by the shell.
In the screenshot below, it is possible to see the duplicate bundle for the shared lib
b2b-mfe-shared
created for the dashboard mfe:Expected behavior We would expect that even for partial builds/deployments the same shared library instance is used. We migrated from Angular 12 and the previous @angular-architects/module-federation version and individual builds/deployments worked fine with that version. We followed the provided tutorial and all seems correctly configured, therefore not sure why we get this behavior.
Build commands used:
Our shell
web.config.js
:One remote mfe (dashboard)
web.config.js
:One of the shared service from lib:
Shell routes for remote mfes:
tsconfig.base.json