-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Function calls are not supported in decorators when fullTemplateTypeCheck is not specified and @dynamic has no effect #23609
Comments
Angular recommends to turn this flag on for packages and libraries https://github.com/angular/angular/blob/master/packages/compiler/design/separate_compilation.md#simplified-options https://angular.io/guide/aot-compiler#fulltemplatetypecheck Also this will solve a lot of issue that people faced recently with `Angular 6` angular/angular#23609
I have this problem too. I tried My repro:
Now attempt to build the npm run build-lib The build fails. The console says BUILD ERROR
Error during template compile of 'NgrxDataModule'
Function calls are not supported in decorators but 'StoreModule' was called.
... Comment out the two ngrx imports in Note that |
Regarding Ward's repro: @wardbell The build will succeed / fail depending on the combination of Build success "skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true "skipTemplateCodegen": false,
"strictMetadataEmit": false "skipTemplateCodegen": false,
"strictMetadataEmit": true,
// fullTemplateTypeCheck omitted (= default value) Build failures "skipTemplateCodegen": true,
"strictMetadataEmit": true,
// fullTemplateTypeCheck omitted (= default value) "skipTemplateCodegen": true,
"strictMetadataEmit": false
// fullTemplateTypeCheck omitted (= default value) ObservationIn Ward's example, setting Side notes / other thoughtsMy experience is that the issue goes down to "everything statically analyzable for AoT" (see "need for static value resoltion" in the compiler docs). Imo, something is broken around the From my experience I can tell that the issue is often produced in Can ngc improve the error message?What will help that ngc prints out the line number in the source code that triggers the error. |
Thanks, @dherges, for figuring out a combination that succeeds. I'm clearly flailing with no clue what these flags are doing to help or hurt. This issue should remain open until Angular makes these choices intelligible and documents appropriately. |
* Inspired by inability to build because of issue angular/angular#23609 * other refactors to satisfy RxJS v6 and lint checks
* tweak collection reducer methods * refactor: NgrxDataModule no longer calls store/effects .forFeature, Inspired by inability to build because of issue angular/angular#23609 * other refactors to satisfy RxJS v6, fix and add tests, and clear many lint errors. * feat: add optional label to EntityAction and EntityActionFactory
Can anyone tell a nub what should I do for now to workaround this issue? |
Are you using the latest angular cli, with a library tsconfig? If not I
suggest to either update to that or update to ng-packagr v3.0.0-rc.3
…On Wed, 09 May 2018 at 15:47, iamimbohacker ***@***.***> wrote:
Can anyone tell a nub what should I do for now to workaround this issue?
I receive it when ng build --prod
i'm using ngx-progressbar
and i get : "Function calls are not supported in decorators but
'NgProgressModule' was called."
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#23609 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQv-WtOWkvdrrvf6luk2S0wYaFWeLaejks5twvNugaJpZM4TsqoI>
.
|
I'm using Angular CLI 6.0.0 only. I do not use ng-packagr |
@dherges I have these but I still get the error when I use the module in AOT |
For more information on why the metadata is elided, as shown in @alan-agius4's screenshot I have a detailed description over at ng-packagr/ng-packagr#860. |
I fixed the error by following #23609 (comment)
I had to remove this @NgModule({
imports: [
// [...]
]
})
export class CoreModule implements OnDestroy {
private static showUserInfo = true;
static forRoot(options: CoreOptions = {}): ModuleWithProviders<NextCoreModule> {
// this line caused the error
// NextCoreModule.showUserInfo = options.showUserInfo ?? true;
return {
ngModule: NextCoreModule,
providers: [
{
provide: APP_INITIALIZER,
useFactory: initialize,
deps: [
ConfigBuilderService, AppKeyService, TranslateService, Title, coreOptionsToken
],
multi: true
},
{ provide: coreOptionsToken, useValue: options || {} }
]
};
}
// [...]
} |
@kroeder You, sir, made my day! Thanks! Does anyone know whether this is documented? And why this happens? |
@JustDoItSaschaRead #36415 and #37126 for details in the implementation. The reason is the Angular compiler has to exactly understand (by only static analysis) what the code means. |
I fixed that by replacing import of |
this works for me: "angularCompilerOptions": { |
@alxhub I created a Library which is not allowed to be published to npm built with Ivy. Therefor I have to use
Error:
This issue is 2,5 years old and has >130 comments. A lot of suggestions from where I dont understand most of them. @alxhub would you mind write down a clear workaround? I wonder what this compiler options do and what downsides they have. And will there be ever a fix for View Engine? If not, and View Engine is required for libraries, then the issue and workaround should be documented in the documentation. Also @SergeyVolynkin @hitallow @bh3605 @antontemchenko would you mind write down why you downvoted @Adrian1907 solution? Sounded like a quick and easy fix, but why isnt it? |
Hey, there; Didn't downvote 😃 ; you probably mistyped me instead |
I'm having the same issue as @MickL but with NgxWebstorageModule.forRoot(). Help, anyone? |
Always make sure that when you're providing a module (inside an npm library / ngc / enableIvy: false) that you're keeping the Classic "Function calls are not supported.." 👿 : @NgModule({})
class MyModule {
static withConfig(
config: Partial<Config> = {}
): ModuleWithProviders<MyModule> {
const mergedConfig: Config = {
...defaultConfig,
...config,
};
return {
ngModule: MyModule,
providers: [
{
provide: MY_VALUE_1,
useValue: mergedConfig.myValue1,
},
{
provide: MY_VALUE_2,
useValue: mergedConfig.myValue2,
},
],
};
}
} Actually working 🤯 : @NgModule({})
class MyModule {
private static withMergedConfig(config: MyConfig) {
return {
ngModule: MyModule,
providers: [
{
provide: MY_VALUE_1,
useValue: config.myValue1,
},
{
provide: MY_VALUE_2,
useValue: config.myValue2,
},
],
};
}
static withConfig(
config: Partial<MyConfig> = {}
): ModuleWithProviders<MyModule> {
return MyModule.withMergedConfig({
...defaultConfig,
...config,
});
}
}
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true,
"fullTemplateTypeCheck": true,
} |
This has arguably been the most annoying error that libraries have had to deal with, and I'm glad that this class of issues has been resolved with the Ivy compiler. With v12 now allowing libraries to be compiled with the Ivy compiler, I am closing this issue as resolved. |
Hey @JoostK Could you share your configuration to publish libraries with Ivy? Locally, with angular v12 and ng-packagr 12, I'm still not allowed to publish libraries with ivy enabled 😞 "scripts": {
"prepublishOnly": "node --eval \"console.error('ERROR: Trying to publish a package that has been compiled by Ivy in full compilation mode. This is not allowed.\\nPlease delete and rebuild the package with Ivy partial compilation mode, before attempting to publish.\\n')\" && exit 1"
} According to official doc, Ivy is still not recommended for libraries:
Thanks in advance for your help 👍 |
@SuperITMan what you're reading is valid for version 9 - 11. Starting with version 12 it's recommended to set
|
That is something we should fix in the docs, then, as it's not the case anymore since v12. Other than that I think I got beaten by @NiklasPor, who has just given the correct answer :) |
Thanks for your quick answers! 😃 You're right, I missed the |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
When building a library and specifying both
skipTemplateCodegen
andstrictMetadataEmit
totrue
, and you try to call a method inside thengModule
decorate exampleRouterModule.forChild([])
this will cause a compilation errorFunction calls are not supported in decorators but 'RouterModule' was called.
When adding
fullTemplateTypeCheck
totrue
the error is not emitted.Also,
@dynamic
seems not to have any effect in this particular case.Expected behavior
No error emitted, or at least that it can be suppressed with the
@dynamic
.I also expect that setting
fullTemplateTypeCheck
doesn't have any effect here as this flag relates more to binding in templates.Minimal reproduction of the problem with instructions
Create a file example
Have tsconfig set with the following options;
When transpiling this will emit an error;
Note when adding
"fullTemplateTypeCheck": true
no error is emitted. (Though this is kinda weird as I don't think this shouldn't have any effect)Reproduction repo: https://github.com/alan-agius4/angular-issue-23609
What is the motivation / use case for changing the behavior?
No error was emitted in NG 5
Environment
Related issues:
ng-packagr/ng-packagr#822
ng-packagr/ng-packagr#778
ng-packagr/ng-packagr#727
ng-packagr/ng-packagr#765
ng-packagr/ng-packagr#767
ng-packagr/ng-packagr#885
The text was updated successfully, but these errors were encountered: