Repository navigation
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
JitCompilerFactory already exported to public api from this #20478
but when i install Angular 5 then start using it got some error in production
my code
export function compilerFactory() { return new JitCompilerFactory([{useJit:true}]).createCompiler() }
ERROR in src/app/app.module.ts(11,9): error TS2554: Expected 0 arguments, but got 1. src/app/dynamic/dynamic.component.ts(17,8): error TS2339: Property 'component' does not exist on type 'DynamicComponent'.
it seems JitCompilerFactory no need arguments, then i tried without arguments
export function compilerFactory() { return new JitCompilerFactory().createCompiler() }
then i got new error
ERROR TypeError: Cannot read property 'useJit' of undefined
i tried manually edit compiler_factory.d.ts
export declare class JitCompilerFactory implements CompilerFactory { private _defaultOptions; constructor(options: CompilerOptions[]) <<< i add this constructor createCompiler(options?: CompilerOptions[]): Compiler; }
after that im trying compile again but got new error :
Uncaught (in promise): Error: Unexpected value 't' imported by the module 'function (){}'. Please add a @NgModule annotation.
Expected behavior
how to fix this, Thanks
Minimal reproduction of the problem with instructions
Environment
Angular version: 5.1.0-beta.2
For Tooling issues:
- Node version: 8.9
- Platform: Mac
Others:
Activity
ocombe commentedon Nov 27, 2017
You shouldn't create the compiler yourself, you need to let the injector do the work here. Look at the code that I used to test it: https://github.com/angular/angular/blob/master/integration/dynamic-compiler/src/app.module.ts
Also I can already tell you that it will fail because of missing metadata when you try to load the lazy module, the reason is that starting from 1.5.1 the cli strips metadata from your bundles when you use aot (to create smaller bundles). I'm not even sure if it'll work in JIT.
The example that I used to test the JitCompilerFactory uses rollup instead of the cli to bundle the lazy loaded module (don't use my setup, it's not optimized, there is no deduplication of modules).
If you want to know why the cli does that, @hansl should be able to answer your questions.
In the mean time, you can use the cli 1.5.0 if you want.
vladuionut commentedon Nov 27, 2017
I have a similar issue, I am trying with the configuration from your test ( https://github.com/angular/angular/blob/master/integration/dynamic-compiler/src/app.module.ts ) but now I got the next error
"Error: No ResourceLoader implementation has been provided. Can't read the url ".
I tried with angular cli 1.5.0.
jackzard commentedon Nov 28, 2017
@ocombe i already use with injector like your test and downgrade to angular cli 1.5.0, but still got metadata error,
i can get out the metadata error by disabling --build-optimizer false, but it make app size larger
VSmirnov17 commentedon Nov 28, 2017
Errors occur when I build project with --aot (ng serve --aot)
If not --aot - all good
ocombe commentedon Nov 28, 2017
Please read what I wrote above: #20639 (comment)
VSmirnov17 commentedon Nov 28, 2017
@ocombe but I use CLI 1.5.0
Sky4CE commentedon Nov 28, 2017
@ocombe , same error here, using

@ngtools/webpackAngularCompilerPlugin plugin. If lazy loaded module contains imported module which is using JitCompilerFactory in a way exactly as you showed here, then I get error:if I build with JIT (at-loader) then everything is working, but I need AOT
You can reproduce it by using angular2-busy lib forked by me to refactor use of JitCompilerFactory:
claygifford commentedon Nov 28, 2017
Using your code...
You get...
ERROR Error: StaticInjectorError[JitCompiler]:
StaticInjectorError[JitCompiler]:
NullInjectorError: No provider for JitCompiler!
mhevery commentedon Nov 28, 2017
Hello, we reviewed this issue and determined that it doesn't fall into the bug report or feature request category. This issue tracker is not suitable for support requests, please repost your issue on StackOverflow using tag
angular.If you are wondering why we don't resolve support issues via the issue tracker, please check out this explanation.
sarunint commentedon Nov 29, 2017
I can confirm that
JitCompilerFactoryis usable.Here is an example plunker: https://embed.plnkr.co/fPLr5wRLJK6CjUjSKoTb/
Sky4CE commentedon Nov 29, 2017
@sarunint , your module is not lazy, this bug appears only in lazy loaded module
sarunint commentedon Nov 30, 2017
@Sky4CE It is lazy. I modified the example a little bit so that you can inspect it from the browser inspector.
I've included a screenshot in case you aren't convinced enough.
VSmirnov17 commentedon Nov 30, 2017
@sarunint You use JIT or AOT?
jackzard commentedon Nov 30, 2017
@sarunint you can't test with SystemJs, bug appear if using AOT + build-optimizer flag..
ocombe commentedon Nov 30, 2017
You cannot use the ngtools package (with or without the CLI), they use optimizations that remove metadata when you compile AoT modules.
If you want to lazy load a module AoT compiled, you have to compile it with ngc directly, not with ngtools, and then bundle it with rollup, webpack, system js bundler or closure compiler
ocombe commentedon Nov 30, 2017
If you think that the CLI should take this use case into consideration and offer a way to bundle without removing those metadata (and I think that they should) then open an issue on the CLI repository please
Sky4CE commentedon Nov 30, 2017
@sarunint , by lazy I mean that it should be loaded inside loadChildren by router, e.g. inside chunk. So in this case it would not work.
claygifford commentedon Nov 30, 2017
I was able to get it to work....
consider this code:
in your module
import {
Compiler,
CompilerFactory,
COMPILER_OPTIONS,
} from '@angular/core';
import {
CompileMetadataResolver,
CompilerConfig,
JitCompiler,
NgModuleResolver
} from "@angular/compiler";
export function createCompiler(compilerFactory: CompilerFactory) {
return compilerFactory.createCompiler();
}
providers: [
{ provide: COMPILER_OPTIONS, useValue: {}, multi: true},
{ provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS]},
{ provide: JitCompiler, useFactory: createCompiler, deps: [CompilerFactory]},
{ provide: CompilerConfig, useValue: new CompilerConfig() }
]
======
then later you can do the following:
Torqode commentedon Nov 30, 2017
@claygifford This works with webpack+JIT, but when I use webpack+AOT I get this error:
vladuionut commentedon Dec 3, 2017
@claygifford @Torqode same here Webpack + AOT doesn't work
vijayanandkannan commentedon Dec 8, 2017
@ocombe, @jackzard Please look into the Issue
JIT Complier needed with AOT Build for Dynamic Component. #20875
I need the JIT Complier @ run time for producing the truly dynamic component. We build with AOT Build which do not work in Angular 5.0. With Angular 4.0 it is working. I am not sure why the feature that was given was taken out. Also what is the alternative?. No one answers except everyone loads the that static HTML as dynamic.
This is the sample of what we do. If you look into app/app.component.ts
In method ngAfterContentInit() {
this.addComponent('<div [formGroup]="_parent.myForm" class="form-row"> ....
http://plnkr.co/edit/rELaWPJ2cDJyCB55deTF?p=preview
All our validation and controls comes from database which is configured.
In angular 4.0 we Implement and create the compiler @ run time (This works perfectly with AOT Build)
import { JitCompilerFactory } from '@angular/compiler';
private compiler: Compiler = new JitCompilerFactory([{ useDebug: false, useJit: true }]).createCompiler();
Please bring back the feature to allow to build with AOT. Tell me the alternative to fix the issue.
Please consider reopening the issue
-Vijay
pkhruasu-ui commentedon Dec 20, 2017
@vladuionut Have you resolve the issue with resourceLoader? I crawl all over the internet and still could not find a way to make it work besides changing from templateUrl to template which is not practical in my situation (100 big components).
vladuionut commentedon Dec 21, 2017
No I don't have a fix for it
Paladinium commentedon Jan 24, 2018
@ocombe : referring to your comment on Nov. 30, I created a feature request for the CLI: angular/angular-cli#9306
It would be nice if you as an Angular contributor could add a comment to the issue to raise the awareness at the CLI team.
I think it is reality that there are use-cases where applications need AOT for the static parts of the app and JIT for dynamic content from the server. In my view, both the CLI and Angular should support this use case properly. Once that is possible, I guess that the number of AOT+JIT related issues will become less.
fix(platform-browser-dynamic): provide a subclass of `Compiler`
angular-automatic-lock-bot commentedon Sep 13, 2019
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.