Repository navigation
Closed
Labels
P5The team acknowledges the request but does not plan to address it, it remains open for discussionThe team acknowledges the request but does not plan to address it, it remains open for discussionarea: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilerfreq1: lowtype: use-case
Milestone
Description
I'm submitting a ... (check one with "x")
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Since 4.0.0, JitCompiler cannot be used with AoT compilation. It's exported from @angular/compiler but its compiled import path is @angular/compiler/src/jit/compiler
app.module.ts
import { NgModule, Compiler } from '@angular/core';
import { JitCompiler } from '@angular/compiler';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [
{
provide: Compiler, useExisting: JitCompiler,
},
]
})
export class AppModule {
}app.module.ngfactory.ts(summary)
import * as import0 from '@angular/core';
import * as import1 from './app.module';
import * as import2 from './app.component.ngfactory';
import * as import3 from '@angular/compiler/src/jit/compiler';
class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
_AppModule_0:import1.AppModule;
__Compiler_1:any;
constructor(parent:import0.Injector) {
super(parent,[import2.AppComponentNgFactory],[import2.AppComponentNgFactory]);
}
get _Compiler_1():any {
if ((this.__Compiler_1 == null)) { (this.__Compiler_1 = this.parent.get(import3.JitCompiler)); }
return this.__Compiler_1;
}@angular/compiler/src/jit/compiler is not existing JS file (because of 4.0.0 FESM). webpack bundling crashes by this problem.
Expected behavior
Resolve JitCompiler from @angular/compiler
Minimal reproduction of the problem with instructions
https://github.com/laco0416/ngrepro-0001
- git clone
- npm install
- npm run ngc
- see the generated files
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
OSX
- Angular version: 4.0.0
-
Language: TypeScript 2.2
-
Node (for AoT issues):
node --version= 6.9.5
Reacted by Maxime Bellec, Max Koretskyi, Leo Caseiro, Michael, May Chan, functionportal, jaa1982, Pankaj Parkar, patrikx3, fmonaldi and 8 more
Reacted by skuby2, jaa1982, patrikx3, Yuriy Grunin and Hadrien TOMA
Metadata
Metadata
Assignees
Labels
P5The team acknowledges the request but does not plan to address it, it remains open for discussionThe team acknowledges the request but does not plan to address it, it remains open for discussionarea: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilerfreq1: lowtype: use-case
Activity
Toxicable commentedon Mar 27, 2017
Just to add to this, you can reproduce it with the CLI aswell.
ng new myprojcd myprojadd to app.module.ts
run
ng serve --aotng serveworks fine howeverand you should get an error similar to
Error: Can't resolve '@angular/compiler/src/jit/compiler' in '...\myproj\src\$$_gendir\app'which indicates the same deep import as @laco0416 pointed out in thengcbuildPaladinium commentedon Apr 15, 2017
Any workaround?
Paladinium commentedon Apr 15, 2017
Here's the workaround using the JitCompilerFactory:
Paladinium commentedon Apr 18, 2017
Yes, I can, but the code to create a module dynamically is complex. It's along the lines of this: http://www.themonkeythemes.com/blog_backoffice/create-components-at-runtime-with-angular
Paladinium commentedon Apr 18, 2017
Yes. We use AOT. Except for one part of the UI that we wanted to build the UI dynamically (based on a server side configuration) which is where we use JIT.
Paladinium commentedon Apr 18, 2017
This is the code that creates a factory for creating a component:
And here's the caller:
And the usage could be:
maxbellec commentedon Apr 18, 2017
I confirm @Paladinium 's workaround (Angular 4.0.1 angular-cli 1.0.0 and similar code to generate dynamic components). Thanks!
98 remaining items
alxhub commentedon May 28, 2020
Hi all,
Indeed, JIT and AOT in Angular with the View Engine runtime were independent - it wasn't really possible to mix and match the two. This was a systemic constraint, not a bug in the implementation.
The good news is that a major design goal for Angular Ivy was to support JIT/AOT interop. In Angular v9+ it's possible to build applications which are AOT compiled but consume dynamic, JIT-compiled components, or even the other way around if desired. There are still a few hiccups (#37216 for example) but overall the support is there.
maxtacco commentedon May 28, 2020
Thank you @alxhub. Just like you said Angular9 works fine for us in AOT mode with some JIT dynamic components. The only issue left is devkit/terser optimizations during AOT builds.
mehtadhaval commentedon Jul 23, 2020
@alxhub : I couldn't find any example of this. Can you point me in right direction ?
alan-agius4 commentedon Nov 10, 2020
Hi all,
AOT+JIT interop with any build optimizations is not a supported path and we don't recommend this approach to be used for production. The main reasons are that this approach increases drastically the bundle sizes, performance overhead and exposes your application to cross-site scripting (XSS) since compiling components at runtime is a XSS vulnerability in itself.
I created an issue to capture and document this: #39624
angular-automatic-lock-bot commentedon Dec 11, 2020
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.