Closed ratsey closed 1 day ago
I have run into the same Problem, and at first thought it might be due to a mismatch in versions between the frontend and the shell. But that wasn't the case.
The problem only occurs once I bump Angular to version 18.2.0
.
@manfredsteyer
I have the same problem if I use angular@18.2.0 and last version of native federation a have severa angular core in my application but in version angular@18.2.0 and native-federation@18.0.2
upd:
but if only build and use simple static server - no problem
update again:)
the problem is here:
in this commit, this is function allow 3 arguments
if remove { write: false }
work correct
I'm in the same boat. Has anyone figured out a solution to this?
I'm using Angular to version 18.1.0
Just to add that using Nx 19.6.0
(Angular ~18.2.0
) the error NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with 'runInInjectionContext'
the error appears when I serve the host application.
Using Nx 19.5.7
(Angular ~18.1.0
) the host works! (at least with the basic configuration).
Hi, I can confirm that fix described in https://github.com/angular-architects/module-federation-plugin/issues/621#issuecomment-2293351616 works.
Running:
on Linux:
sed -i 's/{ write: false },//' node_modules/@angular-architects/native-federation/src/builders/build/builder.js
on MacOS:
sed -i '' 's/{ write: false },//' node_modules/@angular-architects/native-federation/src/builders/build/builder.js
Fixes the problem (at least temporarily).
same issue here and temporary solution works from @klerick, please fix as soon as possible, if it is possible. thx.
Update: remove write: false has impact on old fashion imported libs -> like boostrap v4 or firebase without @angular/fire implementation, what was problem on version native federation v17. So you resolve one and have to resolve other. Update 2: solution has impact on @angular/fire implementation too
After spending so much time trying to figure out what I've done wrong with my new angular 18 app, I've cloned the nf-standalone-solution
and upgraded from 17 (working) to 18, which resulted in the problem again.
I've then changed the version to 18.1 and 18.0 but always the same problem. Can anyone help me? I seem to be the only one having this problem on any version of 18.
Thanks!
I temporarily solved the problem with Krupczak's recommendation, in this case I updated everything to the latest version, but before that, I deleted the node_modules folder, installed it again and then ran the command
After spending so much time trying to figure out what I've done wrong with my new angular 18 app, I've cloned the
nf-standalone-solution
and upgraded from 17 (working) to 18, which resulted in the problem again.I've then changed the version to 18.1 and 18.0 but always the same problem. Can anyone help me? I seem to be the only one having this problem on any version of 18.
Thanks!
we have to wait on @manfredsteyer solution man or will be fixed by angular team
Hi, I can confirm that fix described in #621 (comment) works.
Running:
on Linux:
sed -i 's/{ write: false },//' node_modules/@angular-architects/native-federation/src/builders/build/builder.js
on MacOS:
sed -i '' 's/{ write: false },//' node_modules/@angular-architects/native-federation/src/builders/build/builder.js
Fixes the problem (at least temporarily).
If you want to do this on Windows, you can use the Git Bash cmd and run the linux command
Yep, that worked for me too. It was due to that breaking change in Angular 18.2.0. So as suggested by others:, I patched the builder.js file:
"scripts": {
"ng": "ng",
"workaround:patch:nf": "sed -i 's/{ write: false },//' node_modules/@angular-architects/native-federation/src/builders/build/builder.js",
"start": "yarn workaround:patch:nf && ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
Thanks @alaindeurveilher This script is working for me too. But slight tweak so it works on Mac:
"workaround": sed -i '' 's/{ write: false },//' node_modules/@angular-architects/native-federation/src/builders/build/builder.js",
In case you want to replace it, using javascript:
import { readFileSync, writeFileSync } from 'node:fs';
const path = './node_modules/@angular-architects/native-federation/src/builders/build/builder.js';
const data = readFileSync(path).toString();
writeFileSync(path, data.replace(/\{ write: false }, /, ''));
We have the same issue but decided to go the other way.
We are keeping the versions of angular and native-fedetarion both at ~18.0.x. It was what we used, at the time, for the prototype so we know that it works.
IMHO, patching the package in the node_modules is not worth the work/risk... To many situations were you can end up having to re-patch the file: new version still with the bug or a full re-install of the node_modules packages...
We have the same issue but decided to go the other way.
We are keeping the versions of angular and native-fedetarion both at ~18.0.x. It was what we used, at the time, for the prototype so we know that it works.
IMHO, patching the package in the node_modules is not worth the work/risk... To many situations were you can end up having to re-patch the file: new version still with the bug or a full re-install of the node_modules packages...
native federation 18.1.2 and angular 18.1.* works
so after days of investigation i found out, that the problem is just @angular/build library -> 18.2. is problematic, so this library has to be version 18.1. , others could be 18. . side effects: if you using @angular/fire@18 (analytics), it will stop work, because it works with just @angular/build@18.2. and without upper workaround
so after days of investigation i found out, that the problem is just @angular/build library -> 18.2. is problematic, so this library has to be version 18.1. , others could be 18. . side effects: if you using @angular/fire@18 (analytics), it will stop work, because it works with just @angular/build@18.2. and without upper workaround
Sounds great! Ill have a colleague update the prototype with these versions and test it out...
Hi,
thanks for pointing this out.
I was able to reproduce this issue.
I'm wondering why removing { write: false } helps. I currently don't see the connection.
Ah, I got it: The signature of buildApplicationInternal changed. This parameter does not exist anymore.
Big thanks for pointing this out. I'll make a new version ready.
Just published a new Version: 18.2.1
Today I upgraded to NG18 (specifically 18.2.0) and native-federation 18.1.2. All was working prior to the upgrade.
Now on loading my shell application I get an error:
I'm not directly injecting anything out of context in my code.
Also, when accessing a remote application, I get a circular dependency error:
My federation configs are all very vanilla:
I'm running a mono repo so shell and remote apps are all within the same project and compiled with NG 18.
Edit: add package.json versions: