Closed ghost closed 4 years ago
I think this is probably more of a CLI issue... transferring
This is due to a bug in the CLI, please see https://github.com/angular/angular-cli/issues/17947#issuecomment-644672171.
For now, you can disable Build Optimizer to allow for the JIT compiler to work properly.
Duplicate of https://github.com/angular/angular-cli/issues/17663
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.
π bug report
Affected Package
The issue is caused by package @angular/compiler ### Is this a regression? Yes, the previous version in which this bug was not present was: NG8.2.14 / NG9.0.6 ### Description We operate an app where dynamic component templates are received via an API from the server. These templates get compiled at runtime into an Angular component while the rest of the app gets compiled AOT. Because of the dynamic components we need the Angular JITCompiler to be available at runtime. So basically we have an AOT app including multiple completely dynamic components that can get compiled and rendered whenever it is necessary (whenever templates are received from the server). The dynamic templates are unknown at the time of AOT compilation of the app. This worked in NG 8.2.14 and NG 9.0.6 flawlessly. Afer upgrading to >=NG9.0.7 the compiler gets stripped away in production mode by optimization. This is an issue since it breaks any app depending on runtime compilation. The possible solutions presented in the error are pretty "weird": 1. "JIT compilation is discouraged for production use-cases! Consider AOT mode instead." Yeah, no shit sherlock π as I stated above, the templates that are compiled at runtime are not known at AOT build time. The statement sounds a little bit like "Angular is AOT only so get rid of your dynamic stuff". 2. "Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping" This would be great but does not work. Tried importing it in main.ts or even polyfills.ts Currently we have no way of getting back our much needed runtime compiler. Any help is much appreciated! ## π¬ Minimal Reproductionhttps://github.com/FSDRE/ngcompile
main.ts
, compiler gets importednpm run startProd
-> Error in the browser... ERROR Error: Angular JIT compilation failed: '@angular/compiler' not loaded! - JIT compilation is discouraged for production use-cases! Consider AOT mode instead. - Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'? - Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping. at Se (main.9d222ff640ce74575712.js:1) at Function.get (main.9d222ff640ce74575712.js:1) at Ct (main.9d222ff640ce74575712.js:1) at new mf (main.9d222ff640ce74575712.js:1) at Kh (main.9d222ff640ce74575712.js:1) at e.td [as compileModuleAndAllComponentsSync] (main.9d222ff640ce74575712.js:1) at e.createComponentFactory (main.9d222ff640ce74575712.js:1) at e.ngOnInit (main.9d222ff640ce74575712.js:1) at Rn (main.9d222ff640ce74575712.js:1) at Pn (main.9d222ff640ce74575712.js:1)π Your Environment
Angular Version:
Anything else relevant?