10

I am trying to build app with -aot option (ng build -aot). I’ve got the following error:

ERROR in Error during template compile of 'MyComponent'
  Function calls are not supported in decorators but 'classLogger' was called in 'cLog'
    'cLog' calls 'classLogger'.

However I need this calls and I don’t have an idea how I am supposed to change the code to make it work.

export function classLogger(_classOptions?) {
   const myLogger = new MyLogger();
   myLogger.options = Object.assign({}, defaultClassOptions, _classOptions);

   return myLogger.loggerCB;
}

// export function clog(options = defaultClassOptions): Function {
export function cLog(options?): Function {
   return loggingEnabled ? classLogger(options) : emptyClassDecorator();
}

P.S. Class decorator takes options which must be transferred to decorator patch callback.

zhekaus
  • 3,126
  • 6
  • 23
  • 46

1 Answers1

-1

I also came across with this problem. In my situation I want to override BusyConfig params. App works properly with ng serve but when I want to build app for production Function calls are not supported in decorators but ... exception occurs.

My solution is following: ng build --prod --aot=false

The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code.

ng build --prod is same as ng build --prod --aot

Afsun Khammadli
  • 2,048
  • 4
  • 18
  • 28
  • 4
    Your solution does not solve anything. I came across the problem especially wanting to use AOT. AOT is essential for production. – zhekaus Feb 08 '18 at 14:52