nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.23k stars 2.31k forks source link

Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function' when trying to load host from shell #27711

Open arjuntechgeek opened 2 weeks ago

arjuntechgeek commented 2 weeks ago

Current Behavior

When I try to load local MFE from host/shell I'm getting below error : Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function' I found that angular/core and angular/router is being loaded twice.

Expected Behavior

It should not throw this error.

GitHub Repo

No response

Steps to Reproduce

1.No repo

Nx Report

NX   Report complete - copy this into the issue template

   Node   : 18.17.1
   OS     : darwin-arm64
   npm    : 9.6.7

   nx (global)    : 18.0.2
   nx             : 16.9.1
   @nx/js         : 16.9.1
   @nx/jest       : 16.9.1
   @nx/linter     : 16.9.1
   @nx/workspace  : 16.9.1
   @nx/angular    : 16.9.1
   @nx/cypress    : 16.9.1
   @nx/devkit     : 16.9.1
   @nrwl/tao      : 16.9.1
   @nx/web        : 16.9.1
   @nx/webpack    : 16.9.1
   nx-cloud       : 19.0.0
   typescript     : 5.1.6
   ---------------------------------------
   Community plugins:
   rxjs : 6.5.5

Failure Logs

No response

Package Manager Version

9.6.7

Operating System

Additional Information

No response

Coly010 commented 1 week ago

This should be fixed in latest Nx (v19)

karanodedra20 commented 1 week ago

Hello, we updated to Angular 18 and NX v19 today, but we still have this issue. If I am not wrong, it has been there since Angular v17. We get this issue only for two of our micro FE apps out of about 9-10 and only when we reload the page. I am not sure where to look in the app to fix this, it also seems difficult to reproduce with some demo/example app.

arjuntechgeek commented 1 week ago

This should be fixed in latest Nx (v19)

Do you have any idea why I get this error? This is after migrating to latest version of nx.remoteEntry.mjs:12422 NG0912: Component ID generation collision detected. Components 'ɵEmptyOutletComponent' and 'ɵEmptyOutletComponent' with selector 'ng-component' generated the same component ID. To fix this, you can change the selector of one of those components or add an extra host attribute to force a different ID.