Skip to content

Error rendering a lazy loaded route that dynamically loads a component on ViewContainerRef #50513

@CarlosTorrecillas

Description

@CarlosTorrecillas

🐞 Bug report

What modules are related to this issue?

  • builders
  • common
  • express-engine

Is this a regression?

I think it is, the previous working version I have is Angular 15.2.7

Description

When rendering a page on a lazy loaded module that dynamically renders a component from another module there is an error and the page does not render. The behavior seems similar to what happened here: #37888

🔬 Minimal Reproduction

1.- Clone the repo: https://github.com/CarlosTorrecillas/universal-issue
2.- Do npm i
3.- Do npm run dev:ssr
4.- Navigate to http://localhost:4200/lazy-loaded as in the first URL you paste in the browser or hard refresh on that route

🔥 Exception or Error



Compiled successfully.
** Angular Universal Live Development Server is listening on http://localhost:4200, open your browser on http://localhost:4200 **
Running on the server with appId=ng
Angular is running in development mode.
Running on the server with appId=ng
Angular is running in development mode.
./node_modules/@angular/core/fesm2022/core.mjs:9231
            throw new RuntimeError(205 /* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED */, ngDevMode && 'Injector has already been destroyed.');
                  ^


RuntimeError: NG0205: Injector has already been destroyed.
    at assertNotDestroyed (./node_modules/@angular/core/fesm2022/core.mjs:9231:19)
    at get (./node_modules/@angular/core/fesm2022/core.mjs:9135:14)
    at get (./node_modules/@angular/core/fesm2022/core.mjs:9175:33)
    at get (./node_modules/@angular/core/fesm2022/core.mjs:12979:36)
    at lookupTokenUsingModuleInjector (./node_modules/@angular/core/fesm2022/core.mjs:4417:39)
    at getOrCreateInjectable (./node_modules/@angular/core/fesm2022/core.mjs:4465:12)
    at get (./node_modules/@angular/core/fesm2022/core.mjs:4730:16)
    at get (./node_modules/@angular/core/fesm2022/core.mjs:9175:33)
    at injectInjectorOnly (./node_modules/@angular/core/fesm2022/core.mjs:651:33)
    at Module.ɵɵinject (./node_modules/@angular/core/fesm2022/core.mjs:655:60) {
  code: 205
}

Node.js v18.10.0
A server error has occurred.
node exited with 1 code.

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 16.0.3
Node: 18.10.0
Package Manager: npm 8.19.2
OS: win32 x64

Angular: 16.0.3
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1600.3
@angular-devkit/build-angular   16.0.3
@angular-devkit/core            16.0.3
@angular-devkit/schematics      16.0.3
@nguniversal/builders           16.0.2
@nguniversal/express-engine     16.0.2
@schematics/angular             16.0.3
rxjs                            7.8.1
typescript                      4.9.5

Metadata

Metadata

Assignees

Labels

area: serverIssues related to server-side renderingarea: zonesIssues related to zone.jsregressionIndicates than the issue relates to something that worked in a previous version

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions