-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Error: "inject() must be called from an injection context such as a constructor" when loading remote Angular application from host app #19121
Comments
I even tried to use the new But I still get the same error:
I've added that repro here: |
I cloned the repo and couldn't reproduce this on There is a known issue around using MF with Windows |
@Coly010: What would be a reasonable next step in this? Do I report a bug at the "third-party"? Can I help debug somehow? Edit: I saw your bug here: module-federation/core#1240 Edit2: I can confirm it works fine on Mac. Edit3: Maybe a stupid question, but I can't see the |
I found some differences in the remoteEntry that I guess explains it:
nx@16.8.1
The |
After adding nx/packages/angular/src/utils/mf/utils.ts Lines 109 to 118 in dde9106
The application works fine again. Edit:
Same output from 16.2.2:
I guess something has changed when it comes to generating the Project graph: So obviously something is wrong with the project graph. |
Having the same issue. Node : 16.19.1
OS : win32-x64
npm : 8.19.3
nx (global) : 16.4.0
nx : 16.10.0
@nx/js : 16.10.0
@nx/jest : 16.10.0
@nx/linter : 16.10.0
@nx/workspace : 16.10.0
@nx/angular : 16.10.0
@nx/cypress : 16.10.0
@nx/devkit : 16.10.0
@nx/eslint-plugin : 16.10.0
@nrwl/tao : 16.10.0
@nx/web : 16.10.0
@nx/webpack : 16.10.0
nx-cloud : 16.4.0
typescript : 5.1.6
-------------------------------------------------
Community plugins:
@ngrx/component-store : 16.0.0
@ngrx/effects : 16.0.0
@ngrx/entity : 16.0.0
@ngrx/router-store : 16.0.0
@ngrx/schematics : 16.0.0
@ngrx/store : 16.0.0
@ngrx/store-devtools : 16.0.0 Is there a workaround for this fix? I was logging by doing: shared: (name) => {
// shows all the packages angular core, router etc.,
} but not sure if there are things that may be stated by @JonWallsten regarding Angular? Thanks. 🙂 |
Same issue on 18.0.0
|
I am struggling with the same error, while my colleagues are able to serve the project without any problem. I tried to upgrade and downgrade the versions of both Angular and Nx, but it did not work for me. Also, I tried to copy the entirety of the node_modules from one of my teammates, but still had no luck.I don't think it's related but I also checked the ports where i need to serve the apps on angular v 16.2.9 |
I think there are multiple causes for this issue. |
i ve several angular applications with different versions and structures. i am able to serve the nx project with ng v16 and nx v16 without any problem. as for the problematic application where i get this error has ng v16.2 and nx17 v. still trying to figure out the root cause of the issue. |
still i could not realize the root cause of the issue but i ve managed to get it worked by installing the packages with yarn. i am guessing something was wrong with package-lock file and project graphs |
I can confirm that this issue exists on latest version(18.0.6). I have had this when I had package-lock.json included in .nxignore and excluded from namedInputs. Workaround is remove package-lock.json from those places, but in my project I have version in this file and version bumping doesn't work correctly with nx affected (too many apps/libs is affected). We need something similar to implicitDependencies to mark which sections of this file can affected, that was in previous nx versions. |
any updates? |
Any updates on this? I have reproduced this issue on two different mac machines. so this is not windows specific |
any updates? same on mac machine |
Fo me I setuped new workspace with latest then put the host and some
remotes and it worked so maybe you should sync your workspace with latest
including the dependencies
…On Mon, Apr 8, 2024, 8:39 AM Ilya ***@***.***> wrote:
Reinstall node_modules helped me
my config
image.png (view on web)
<https://github.com/nrwl/nx/assets/57585370/82acb09f-bb08-46e4-9b2f-d0edf5705344>
—
Reply to this email directly, view it on GitHub
<#19121 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKIXF7TXKBHXAHYF2JO5P43Y4I3SLAVCNFSM6AAAAAA4U3B5W6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRHE3TAOBRGA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Buenas, he tenido el mismo problema, la solución ha sido actualizar las dependencias del proyecto a la última en su momento El hecho es que tengo una librería desarrollada en V17 y me estaba dando este error. Actualización [27/04/2024] La actualización no funcionó SOLUCIONADO "preserveSymlinks": true |
Hi all! I'm sorry I missed this issue for some time. We definitely had some issues with our lockfile parsing which is used to find dependencies of projects which would seem to be the root cause of many of the issues outlined here. However, we have resolved that now. As per @adacostac message, if you are using a package manager that uses symlinks (pnpm for example), you should provide Also, you must ensure all your hosts and remotes use the same version of Angular. Unfortunately this is a restriction from Angular and not us or Module Federation. Angular relies on the singleton pattern, and therefore when there are different versions of angular packages, new instances are created which break the singleton pattern. Something that we should have done, and I will do now, however, is to add |
…kage #19121 (#23464) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> In our Module Federation utils for Angular, we set some packages that should always be shared. This array was missing `@angular/core` which should be shared at all times for DI to function as expected ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Ensure `@angular/core` is shared ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #19121
…kage #19121 (#23464) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> In our Module Federation utils for Angular, we set some packages that should always be shared. This array was missing `@angular/core` which should be shared at all times for DI to function as expected ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Ensure `@angular/core` is shared ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #19121 (cherry picked from commit 4315e91)
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
After migrating NX from 16.2.2 -> 16.8.1 our remote (using module federation) applications failes with this error:
They work as standalone applications but not remotes. I.e when I go to
http://locahost:4201
it loads the dashboard, but not when trying to load it as a route in our host-app.It might be related to this issue:
#17696
And/or maybe this issue:
angular/angular#51532
The module federation is setup according to the guide.
Expected Behavior
It should not fail to run the application as a remote application using module federation.
GitHub Repo
https://github.com/JonWallsten/nx-repro
Steps to Reproduce
Or from scratch:
Nx Report
Failure Logs
Package Manager Version
9.3.1
Operating System
Additional Information
The text was updated successfully, but these errors were encountered: