ngx-formly: Error during template compile of 'module'. Function calls are not supported in decorators but 'FormlyModule' was called.

I’m submitting a … (check one with “x”)

[x] bug report => The issues that are similiar talk about aot compilation issues, but we don’t have aot set to true [ ] feature request [ ] support request

Current behavior My team has a build process that will run @angular/compiler-cli/src/main.js --project src/tsconfig.app.json. Keep in mind that running this has been working for us until I updated to Angular 6. The error we receive seems to be from the FormlyModule, because it started failing once I updated @ngx-formly/core from 2.x.x to 4.4.4 since I am using Angular 6. Also, note that I have tried to use every 4.x version (4.0.0, 4.0.1, 4.0.2, 4.0.3, 4.1.0, 4.4.2, 4.4.4, etc). I am receiving the following error:

Error during template compile of 'FormViewerDefaultsModule'
  Function calls are not supported in decorators but 'FormlyModule' was called.

In further investigation, it looks like it gives the error when I call forRoot on the FormlyModule. Here is the module that its failing on:

import { CommonModule } from "@angular/common"
import { NgModule } from "@angular/core"
import { FormsModule, ReactiveFormsModule } from "@angular/forms"
import { FormlyModule } from "@ngx-formly/core"
import { TranslateModule } from "@ngx-translate/core"
...
import { DEFAULT_FORMLY_CONFIG, DEFAULT_VIEWER_CONFIG, FIELD_TYPE_COMPONENTS } from "./form-viewer-defaults.config"

@NgModule({
  declarations: FIELD_TYPE_COMPONENTS,
  exports: [
    ...,
    FormlyModule,
  ],
  imports: [
    CommonModule,
    FormsModule,
    ...,
    ReactiveFormsModule,
    FormlyModule.forRoot(DEFAULT_FORMLY_CONFIG),
  ],
  providers: [
    LineItemService,
  ],
})
export class FormViewerDefaultsModule {}

Notice that I call forRoot. This is when I receive the error above. However, when I remove the forRoot like below, it works:

  imports: [
    ...,
    FormlyModule,
  ],

Expected behavior I need to pass in the config, for obvious reasons.

Minimal reproduction of the problem with instructions Due to the fact that this is a compiler issue, I can’t use stackblitz. Running ng serve works perfectly, so stackblitz isn’t useful. I’m hoping what I have posted is enough for get some help.

Please tell us about your environment:

Any ideas on what this could be?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

try with:

import { FormlyConfig } from '@ngx-formly/core';
import { ɵc as FormlyGroup } from '@ngx-formly/core';
import { ɵa as FORMLY_CONFIG_TOKEN } from '@ngx-formly/core';
import { ɵb as FormlyFormExpression } from '@ngx-formly/core';