Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASL Angular: Function calls are not supported... #270

Closed
ghost opened this issue Mar 2, 2020 · 7 comments
Closed

CASL Angular: Function calls are not supported... #270

ghost opened this issue Mar 2, 2020 · 7 comments
Labels

Comments

@ghost
Copy link

ghost commented Mar 2, 2020

Hello,
Recently, when I try to extract i18n messages from source code with command...

ng xi18n myproject --output-path src/locale && ngx-extractor -i src/**/*.ts -o src/locale/messages.xlf

...the process interrupts and an error is thrown:

ERROR in Error during template compile of 'AppModule'
    Function calls are not supported in decorators but 'AbilityModule' was called.
Unexpected value 'undefined' imported by the module 'AppModule in <path>/src/app/app.module.ts'
Error during template compile of 'AppModule'
    Function calls are not supported in decorators but 'AbilityModule' was called.

I have AbilityModule included in AppModule just like the documentation shows.
I have Angular v9.0.3 running.

Any help is appreciated.

@stalniy
Copy link
Owner

stalniy commented Mar 3, 2020

Hello,

Did you enable Ivy? According to https://medium.com/angular-in-depth/solving-aot-error-in-ngrx-function-calls-are-not-supported-in-decorators-5c337381457a this error is not thrown if you use Ivy

@stalniy
Copy link
Owner

stalniy commented Mar 3, 2020

If you cannot enable Ivy don’t use forRoot method and just use AbilityModule, and create provider for Ability manually according to the article.

@ghost
Copy link
Author

ghost commented Mar 3, 2020

Thank you for the answer.

I have Ivy enabled.
Removing forRoot and use only AbilityModule leads to another error:
Unexpected value 'undefined' exported by the module

@stalniy
Copy link
Owner

stalniy commented Mar 4, 2020

Do you use the latest version of @casl/angular?

@ghost
Copy link
Author

ghost commented Mar 5, 2020

Yes, I am using the latest version.

@stalniy
Copy link
Owner

stalniy commented Mar 6, 2020

OK, I've tried to migrate casl/angular to 9.x and got similar errors during ng update process. But when I run ng serve and ng build, everything is fine - app works as expected and without errors.

Update: but yes, ng xi18n shows the same error, will investigate today. Thanks for the issue!

@stalniy stalniy added the bug label Mar 6, 2020
@stalniy stalniy closed this as completed in b883118 Mar 6, 2020
@stalniy
Copy link
Owner

stalniy commented Mar 6, 2020

Ohhh... I hate angular with all its overengeenering... I spent the whole day to understand where the issue is.

Unexpectedly angular team doesn't recommend to use Ivy for library authors because something was not settled down in its API - https://indepth.dev/the-angular-ivy-guide-for-library-authors/ . Instead they suggest to publish View Engine compatible code and use ngcc in the app to magically rewrite libraries to support Ivy... But obviously ngcc expects code to be built in a specific way or buy specific tools (like ng or ngc), otherwise it cannot detect the places which needs to be rewritten and shows extremely strange errors in the terminal

The long story short. It's angular. It always was like this starting from 1.x.

The issue is fixed, enjoy ;) Published in @casl/angular@3.0.6

stalniy added a commit to stalniy/casl-angular-example that referenced this issue Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant