Closed kindy91 closed 1 year ago
I can't reproduce this on a fresh 15.9.2 workspace, nor does our generators generate anything that uses the inject()
function. This would lead me to believe the error is in code that you've written.
I'd need a repo or a more detailed reproduction to help further.
Hi, here I created an example repo with the bug. https://github.com/kindy91/failing-microfrontends
Please npm install
and then npm run start
.
Here's a snapshot of the result where instead of getting a page with 2 routes to cart and shop, i get the following error.
Can you talk me through the steps you did to create this repo?
I can see the issue in your repo, but if I create this same structure from scratch, I don't receive any problems.
I did the following:
npx -y create-nx-workspace@latest pkgmf
and then selected Package Based Reponpm install @nrwl/angular
nx g host shell --remotes=shop,cart
nx serve shell
And it all works fine.
I can't see any obvious differences between your repo and the one I've created.
Can you talk me through what you did to create the repo and the MF apps?
I did the following in the example repo:
npx create-nx-workspace
package.json
was 14.8.8
. So afterward, I upgrade the versions in the package.json
to of nx
and @nrwl/*
packages to 15.9.2
. In addition, I add to the package @nrwl/angular:15.9.2
, and finally I run npm install
.nx g @nrwl/angular:host shell --remotes=shop,cart --e2eTestRunner=none
and choose scss.nx serve shell --devRemotes=shop,cart
.The only difference I see is that you created the workspace with @latest
while I upgraded the version by hand in the package.json.
I don't see why this should produce a bug though. Unless there needs to be some certain migration script needed for v14.8.8 to go to v15.9.2.
First commit https://github.com/kindy91/failing-microfrontends/commit/4401586f0efe919e3913ed3cd0f5fde0254d0a8a#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519 Second commit https://github.com/kindy91/failing-microfrontends/commit/cb64bda053692eead40982578e478e4f70ea3b2b#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
By the way, upgrading to nrwl 16 fixed this issue.
I have the same error following the steps of the guide https://nx.dev/more-concepts/micro-frontend-architecture
I tried with 15.9.3 and 16.0.0... and get the same error...
For 15.9.3...
For 16.0.0...
@ekiliqua did you try removing node_modules
, package-lock.json
and then npm cache clear --force
and then npm install
? It should work for v.16.0.0
I think
Hi, thank you for you answer.
Yes, I tried removing node_modules, clearing cache and with nx@15 and nx@16... I don't know what else to do... Same error.
I have installed node 18.15
These are my package.jsons in both cases.
The only difference I see is that you created the workspace with @latest while I upgraded the version by hand in the package.json. I don't see why this should produce a bug though. Unless there needs to be some certain migration script needed for v14.8.8 to go to v15.9.2.
We don't recommend upgrading Nx by manually changing versions. Should use nx migrate
. Glad that v16 has it working for you.
@ekiliqua I'll take a look
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
I got the same problem on latest version nx (16.2.2). I use the following commands: npx create-nx-workspace@latest mf npm install --save-dev @nx/angular nx g @nx/angular:host shell --remotes=test nx serve shell --devRemotes=test
On one of my projects for a larger codebase, I can run my MFEs on Nx 16.2.2 but I get the NG0203 error when upgrading as soon as Nx 16.3.0-beta.x and it remains even through the Nx 16.4.x-beta.1 release.
My shell uses webpack.config.ts
const { withModuleFederation } = require('@nx/angular/module-federation');
const config = require('./module-federation.config');
module.exports = withModuleFederation(config).then((webpackConfigFunc) =>
webpackConfigFunc({
output: {
scriptType: 'text/javascript',
},
}),
);
And my remotes use
const { withModuleFederation } = require('@nx/angular/module-federation');
const config = require('./module-federation.config');
module.exports = withModuleFederation(config);
Nothing else too fancy.
I don't know if this matters at all but I notice that the migrations never upgrade peerDeps in libraries. Perhaps we should include this in nx repair
as well, or at a minimum display warnings in the console?
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
Inspired from https://nx.dev/more-concepts/micro-frontend-architecture, I have an angular workspace with one shell frontend and 2 remoteDevs frontends ( call them remote-dev1, and remote-dev2 ) that can be open by route change to /remote-dev1 and /remote-dev2 consequtively.
The application when running shows the shell frontend. In the Frontend, there are two links that route to /remote-dev1 and /remote-dev2.
The routing used work fine, and the corresponding microfrontends used to open on route change. However, since updating to nx version 15.9.*, it became buggy. The route change files, and i remain on the shell frontend. In the console, i get an angular core error that says
inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with EnvironmentInjector#runInContext.
.Expected Behavior
I should be routed to the corresponding remoteDevs frontends.
GitHub Repo
No response
Steps to Reproduce
Nx Report
Failure Logs
Additional Information
No response