Function calls are not supported in decorators but 'FileTypeModule' was called
Asked Answered
J

2

20

trying to setup ngx-formly-material-file, but I got an error: Function calls are not supported in decorators but 'FileTypeModule' was called

I tried to export FileTypeModule, but got the same error

export const fileTypeModule = FileTypeModule.forRoot();

@NgModule({
  imports: [fileTypeModule]

})
Joanajoane answered 20/1, 2020 at 12:4 Comment(0)
C
38

Have seen this happening many times, last time, with Angular 9, happened during ng build <my-library>, for all modules that were initialized with forRoot

I added in tsconfig.lib.json this and the error went away.

 "angularCompilerOptions": {
    "fullTemplateTypeCheck": true
  }

The fullTemplateTypeCheck compiler switch actually enables the binding expression validation phase of the template compiler. See more details here.

Collaboration answered 11/5, 2020 at 19:41 Comment(1)
Works for me too!!Bernini
G
5

Function calls are not supported in decorators but 'FileTypeModule' was called

I don't have good news about this error message.

It is an issue with Angular 8.2.x and up that introduced limitations on how you can generate metadata for NgModule that are side effects from recent updates to support Ivy.

export const fileTypeModule = FileTypeModule.forRoot();

The only way to fix this error is to modify the function forRoot() from the module. There are strict limitations on what can be done inside that function.

You can not dynamically generate any providers, use arrow functions or conditionally create a NgModule metadata.

This error has a long history now across multiple libraries:

https://github.com/ng-packagr/ng-packagr/issues/727

https://github.com/angular/angular/issues/23609

You can find my specific ways of fixing this problem here:

https://github.com/angular/angular/issues/23609#issuecomment-561615821

If you are not the author for the FileTypeModule the only work around is to contact the author and request that they fix the problem, or you fork the library and make the fixes yourself.

Greywacke answered 20/1, 2020 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.