I have created an angular with ASP .NET Core sample. when i try to run my angular application only using below command it is working fine
ng serve --prod
But when i set buildOptimizer and aot to false application throws error


Download sample
goto ClientApp folder
give npm i command
then give ng serve --prod
You will see reported error in console window
"@angular/animations": "6.1.10",
"@angular/common": "6.1.10",
"@angular/compiler": "6.1.10",
"@angular/core": "6.1.10",
"@angular/forms": "6.1.10",
"@angular/http": "6.1.10",
"@angular/platform-browser": "6.1.10",
"@angular/platform-browser-dynamic": "6.1.10",
"@angular/platform-server": "6.1.10",
"@angular/router": "6.1.10",
Hi @alan-agius4 ,
Do you have any idea about this, please share it
The problem seems to be that you have optimization: true, Most likely there some non side effect code free which being removed.
okay @alan-agius4 馃憤
If you run ng serve --prod --source-map you can see where the error comes from:

That being said, even with that extra information the best I can see is that something breaks inside that library. Maybe it's a bug somewhere...
Can you try with the latest Angular CLI though? You are using version 6 and a lot of changed since then. Maybe the problem has been fixed.
okay @filipesilva , i will try with angular 8.
If there is a bug in my library thenm why it works fine with optimization true
Using optimization set to true will try to remove unused code. Maybe the problematic code is removed and thus it doesn't error at runtime.
Closing as stale. If you're still having this problem with the latest versions let us know with a repro and we can reopen.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
The problem seems to be that you have
optimization: true, Most likely there some non side effect code free which being removed.