Micarle
Micarle

Reputation: 141

angular2 AoT error Function calls are not supported

When I use angular2 AoT, I get an error:

 Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 54:17 in the original .ts file), resolving symbol COMPILER_PROVIDERS in

and in my Directive Module, I have code like this:

import { COMPILER_PROVIDERS } from '@angular/compiler';
@NgModule({
/*imports ...*/
providers: [
    COMPILER_PROVIDERS,
]
})

I understand that I should change the COMPILER_PROVIDERS to an exported function, But when I check the source code of @angular/compiler, I find this:

export declare const COMPILER_PROVIDERS: Array<any | Type<any> | {
    [k: string]: any;
} | any[]>;

export declare class RuntimeCompilerFactory implements CompilerFactory {
    private _defaultOptions;
    constructor(defaultOptions: CompilerOptions[]);
    createCompiler(options?: CompilerOptions[]): Compiler;
}

I don't know how the COMPILER_PROVIDERS works, and I don't know how to transfer it to a exported function in my module.

Upvotes: 3

Views: 1041

Answers (1)

8192K
8192K

Reputation: 5290

The solution is to not use COMPILER_PROVIDERS any more. Also, you do not need to include JitCompiler in your list of providers.

Instead, use JitCompilerFactory from "@angular/compiler". It is not injectable, so just create a new instance of it yourself like this:

private compiler: Compiler = new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler();

The rest works as before, for example following Radim Kohler's excellent answer here.

Upvotes: 9

Related Questions