New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.0.0] bug(compiler-cli): Cannot use JitCompiler with AoT #15510
Comments
Just to add to this, you can reproduce it with the CLI aswell.
run |
Same error for me. |
Any workaround? |
use JIT only and wait until AOT is workling together at once... :) If you need JIT with AOT together anyway you will have larger bundle so it is possible same time any way... You will be the same any way. |
Here's the workaround using the JitCompilerFactory:
|
@Paladinium are you able to create dynamic component with JIT? Right now I still get a |
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 Sorry, my error, are you able to compile with AOT? So AOT + JIT? |
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 Do you have an example? I use the same code, but it shows |
This is the code that creates a factory for creating a component:
And here's the caller:
And the usage could be:
|
I confirm @Paladinium 's workaround (Angular 4.0.1 angular-cli 1.0.0 and similar code to generate dynamic components). Thanks! |
I get the same error Looks like the component is decorated, but the module is missing something somewhere. I get the same code. |
Are you guys using 4.0.1 or 4.0.2? Is it the same for you? What is you app and module settings? :) |
On 4.0.1. Below are my module settings. To generate components, my code is similar to that of @Paladinium, and derived from http://stackoverflow.com/a/38888009/3218806
|
end this is aot right? because same code component generator for me, all same, and my bundle is bigger with aot as well, but it is giving same error. jit working with aot not, so weird. are you sure you using aot??? |
@maxbellec , yes, right, this is where I got the original code from. @patrikx3 : yes, we're using AOT. It seems to be that you should open a question on stackoverflow since it has nothing to do with this issue. |
My bad, actually my code compiles with AOT but I still get the |
you must be using JIT, instead AOT. for sure!!!! i tested all, the same code in 2.3 (angular-cli), 4.0, 4.0.1, 4.0.2, i understand the compiler how to create dynamic components and dynamic modules and even the angular guys say that you cannot create a dynamic module, so you are using JIT!!! for sure! |
i am a pro in compiling in angular by now.. by hand... works even with 2G fast, max 15 seconds, from above 3G is fast! i had to turn off JIT because it was not doing anything and solved in a different way. |
@maxbellec : no, I never had this problem. I recommend opening a stackoverflow to not spam this bugreport with an application specific issue. Sounds to me like TemplateModule is not annotated with @NgModule. Or maybe check your tsconfig file that you need for AOT. For example the compiler options:
|
your build is JIT, you just think it is AOT. you are the one with AOT creating modules on the fly |
@Paladinium given the many discussions and workarounds found, I also doubt (but I hope you're right) you are actually using AOT AND making JITCompiler work. Many well informed people (including contributors) seem to suggest it is not possible. Can you triple check everything works for you? If yes, could you provide a working plunker? It would make many people's life easier. |
@maxbellec : @Paladinium 's build is 100% is JIT!!! I tested all! v2, v4 , using angular-cli, my own , and always same error. how come angular-cli is wrong same error??? :) @Paladinium it is a miracle for you! i wish i get it as well!! :) :) :) 👍 |
@maxbellec : I can provide you a ZIP that you can try ourself (see attachment). To run:
I suggest you start with looking at the app.component.html which includes the same component twice: once 'normally' and once using the dynamic-ui component which gets a string (here with a component called 'some-component', but it could also be just HTML or both) that is then compiled using JIT and inserted into the page. Just to not get confused: yes, 'some-component' is pre-compiled by AOT. But the string passed to the dynamic-ui component needs to be compiled and interpreted by Angular - which is the step where the JIT compiler is needed. One more thing: I never said it can be done using the angular CLI. We created our own build based on Webpack 2 and I'm not saying that it's perfect. However, it manages the complexity of switching between JIT and AOT for dev and prod mode. Also note that among others, the entry points are different: main.browser.ts and main.browser.aot.ts. I'm sure there is much to be improved in the given example, but for sure: it shows how to dynamically create a UI using JIT within an AOT compiled application. Let me know what you think. |
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. |
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. |
@alxhub : I couldn't find any example of this. Can you point me in right direction ? |
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 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
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
app.module.ngfactory.ts(summary)
@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
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
OSX
Language: TypeScript 2.2
Node (for AoT issues):
node --version
= 6.9.5The text was updated successfully, but these errors were encountered: