Function calls are not supported in decorator
Asked Answered
S

1

11

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.

Stinking answered 31/12, 2017 at 13:49 Comment(1)
looks like @angular/cli 1.6.8 solved the problem...Stinking
C
-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

Chemistry answered 2/2, 2018 at 7:37 Comment(1)
Your solution does not solve anything. I came across the problem especially wanting to use AOT. AOT is essential for production.Stinking

© 2022 - 2024 — McMap. All rights reserved.