Angular 9+ & ASP.NET Core Engine Not working with IVY
See original GitHub issueSo I am working with .NET CORE version 2.2
and Angular version ~10.0.6
and I read angular documentation and have found that when Angular 8 is updated to Angular 9.
A new compiler is added to Angular project that is Ivy, when we do SSR without IVY OR with Angular below 9 , No exception or error is coming from the below code, but when working with Ivy, it is causing problem.
Please let me know if you know any solution to this.
🐞 Bug report
What modules are related to this issue?
- aspnetcore-engine
- builders
- common
- express-engine
- hapi-engine
Is this a regression?
✍️Yes, the previous version in which this bug was not present was: Angular 8 and below It works perfectly below Angular 9 since this error is coming from Angular Ivy, This needs to be properly documented and resolved. Mostly errors I have seen related to Angular Universal V9 is due to IVY, Guide me if there is any way to look the code of ngAspnetCoreEngine() so that we can check the point from which issue is generating.
Description
🔥 Line on Which exception is taking place
export default createServerRenderer((params) => {
//console.log("=============================================")
//console.log("Working");
//console.log("=============================================")
// Platform-server provider configuration
const setupOptions: IEngineOptions = {
appSelector: '<app-root></app-root>',
ngModule: AppServerModule,
request: params,
providers: [
// Optional - Any other Server providers you want to pass
// (remember you'll have to provide them for the Browser as well)
]
};
//console.log("=============================================")
//console.log("Working");
//console.log("=============================================")
return ngAspnetCoreEngine(setupOptions) // App Crashing in Promise return
.then(response => {
//console.log("=============================================")
//console.log("App is crashed in above return of Promise, build file which breaks code is attached below");
//console.log("=============================================")
return ({
html: response.html
});
})
.catch(e => {
return ({
html: "App is crashing, caught in catch method of createServerRenderer()"
});
})
});
🔥 build file code that is breaking exception
class R3Injector {
destroy() { // This function is called when using IVY compiler, and this throw below exception
// If we remove this 5 lines code, It works perfectly fine. but cant remove directly after every build so we need permanent solution
this.assertNotDestroyed(), this._destroyed = !0;
try {
this.onDestroy.forEach(service => service.ngOnDestroy())
} finally {
this.records.clear(), this.onDestroy.clear(), this.injectorDefTypes.clear()
}
}
A clear and concise description of the problem...
🔬 Minimal Reproduction
Before Exception Error Logs
Microsoft.AspNetCore.NodeServices:Information: What's our REQUEST Object look like?
Microsoft.AspNetCore.NodeServices:Information: The Request object only really exists on the Server, but on the Browser we can at least see Cookies
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: AppComponent Constructor is called!
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: AppComponent NgOninit is called!
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: ==========================================
Microsoft.AspNetCore.NodeServices:Information: AppComponent Destructor is called!
Microsoft.AspNetCore.NodeServices:Information: ==========================================
// Now this is the place where code is crashing
**Exception thrown: 'Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action method** WebApplicationBasic.Controllers.HomeController.Index (Angular-DotNetCore-SSr), returned result Microsoft.AspNetCore.Mvc.ViewResult in 432.0046ms.
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executing ViewResult, running view Index.
🔥 Exception or Error
Injector has already been destroyed. Error: Injector has already been destroyed. at R3Injector.assertNotDestroyed
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCoreSSr\ClientApp\dist\ClientApp\server\main.js:1:352374)
at R3Injector.get (C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:351120) at NgModuleRef$1.get (C:\Users\umer.hasan\source\repos\Angular-
DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:523603) at
C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-
SSr\ClientApp\dist\ClientApp\server\main.js:1:1516636 at Generator.next () at fulfilled
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:2194411) at ZoneDelegate.invoke (C:\Users\umer.hasan\source\repos\Angular-
DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:1841674) at Zone.run
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-
SSr\ClientApp\dist\ClientApp\server\main.js:1:1834088) at C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-
DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:1853185 at ZoneDelegate.invokeTask
(C:\Users\umer.hasan\source\repos\Angular-DotNetCore-SSr\Angular-DotNetCore-SSr\ClientApp\dist\ClientApp\server\main.js:1:1842606)
🌍 Your Environment
PM> ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ â–³ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 10.0.6
Node: 12.18.3
OS: win32 x64
Angular: 10.0.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.6
@angular-devkit/build-angular 0.1000.6
@angular-devkit/build-optimizer 0.1000.6
@angular-devkit/build-webpack 0.1000.6
@angular-devkit/core 10.0.6
@angular-devkit/schematics 10.0.6
@angular/cli 10.0.6
@ngtools/webpack 10.0.6
@nguniversal/aspnetcore-engine 10.0.2
@nguniversal/builders 10.0.2
@nguniversal/common 10.0.2
@nguniversal/express-engine 10.0.2
@schematics/angular 10.0.6
@schematics/update 0.1000.6
rxjs 6.5.5
typescript 3.9.7
webpack 4.43.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Bug confirmed and working on a fix.
More context: https://github.com/angular/angular/issues/37888#issuecomment-758859207
@patelhr, this seems a different issue. Mind opening a new issue with a reproduction? Thanks.