Repository navigation
Description
I'm submitting a...
[X] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
Current behavior
When building a library and specifying both skipTemplateCodegen and strictMetadataEmit to true, and you try to call a method inside the ngModule decorate example RouterModule.forChild([]) this will cause a compilation error Function calls are not supported in decorators but 'RouterModule' was called.
When adding fullTemplateTypeCheck to true 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
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
@NgModule({
imports: [
RouterModule.forChild([])
]
})
export class LibModule { }Have tsconfig set with the following options;
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true
}
When transpiling this will emit an error;
Error during template compile of 'LibModule' Function calls are not supported in decorators but 'RouterModule' was called.
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
Angular version: 6.0.0-rc-6
Related issues:
https://github.com/dherges/ng-packagr/issues/822
https://github.com/dherges/ng-packagr/issues/778
https://github.com/dherges/ng-packagr/issues/727
https://github.com/dherges/ng-packagr/issues/765
https://github.com/dherges/ng-packagr/issues/767
https://github.com/dherges/ng-packagr/issues/885
Activity
[-]Function calls are not supported in decorators when fullTemplateTypeCheck is not specified[/-][+]Function calls are not supported in decorators when fullTemplateTypeCheck is not specified and @dynamic has no effect[/+]alan-agius4 commentedon Apr 30, 2018
Added a small repo reproducing this.
From my quick debug, It looks like the
static_reflectoris not resolvingmembers/staticsproperly. As for instance theRouterModuleshould have aforChildmember.feat: enable `fullTemplateTypeCheck` (#826)
wardbell commentedon May 5, 2018
I have this problem too. I tried
fullTemplateTypeCheckinlib/tsconfig.jsonand it made no difference.My repro:
Now attempt to build the
ngrx-datalibraryThe build fails. The console says
Comment out the two ngrx imports in
NgrxDataModule(leaving theFooModule) and try building again.This time the build succeeds and generates a package in
dist.Note that
FooModuleis just fine.dherges commentedon May 6, 2018
Regarding Ward's repro: @wardbell
The build will succeed / fail depending on the combination of
angularCompilerOptions. Added one example in this reproBuild success
Build failures
Observation
In Ward's example, setting
"skipTemplateCodegen": truerequires that"fullTemplateTypeCheck": trueis also enabled to get a success build from ngc.Side notes / other thoughts
My 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
strictMetadataEmitoption or my understanding of the option is horribly broken 😆From my experience I can tell that the issue is often produced in
static forRoot(): ModuleWithProviders, sometimes depending on one line of code that becomes or becomes not "statically analyzable". Of course, I don't have reliable repros and I also don't want to speculate on some vague memories of code that I've seen working / non-working.Can ngc improve the error message?
What will help that ngc prints out the line number in the source code that triggers the error.
wardbell commentedon May 7, 2018
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.
refactor: NgrxDataModule no longer calls store/effects .forFeature
breaking changes: update to Angular/RxJS/Ngrx v6 v6.0.0-beta.1 (#147)
123 remaining items
aescobar-icc commentedon Jan 9, 2021
this works for me:
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
MickL commentedon Jan 20, 2021
@alxhub I created a Library which is not allowed to be published to npm built with Ivy. Therefor I have to use
ng build --prodwhich uses View Engine. But when I do so, I cant built: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?
SergeyVolynkin commentedon Jan 20, 2021
Hey, there; Didn't downvote 😃 ; you probably mistyped me instead
@SergeyMellTheRealOha commentedon Mar 31, 2021
I'm having the same issue as @MickL but with NgxWebstorageModule.forRoot().
I have the PrimeNg 11 Table as part of my library, which throws a very strange error when it's not compiled with Ivy.
To circumvent this I set "fullTemplateTypeCheck": false", which seemed to remove the need to build with Ivy, but now I'm stuck with the same thing as Mick.
Anyone's got a solution?
I found that people were advising to build Libs that are only publisehd to internal NPM repos with Ivy by removing prebublishOnly from package.json, but I don't even have this set anywhere in my package.json, therefore I don't know how to remove it.
However, this also is only a workaround and doesn't really fix the whole problem, that libs are not supposed to be built with Ivy but if you try to omit Ivy, you're stuck with problems like the one described here.
Help, anyone?
NiklasPor commentedon May 4, 2021
Always make sure that when you're providing a module (inside an npm library / ngc / enableIvy: false) that you're keeping the
withConfigforRootmethods as simple one liners. For example I had to remove the simple assignment at the start and move it into a parameter, instead of creating a variable:Classic "Function calls are not supported.." 👿 :
Actually working 🤯 :
tsconfig.json(like already suggested above):JoostK commentedon May 14, 2021
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.
SuperITMan commentedon Jun 9, 2021
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 😞
Angular compiler-cli is still adding the following script in "package.json":
According to official doc, Ivy is still not recommended for libraries:
Thanks in advance for your help 👍
NiklasPor commentedon Jun 9, 2021
@SuperITMan what you're reading is valid for version 9 - 11.
Starting with version 12 it's recommended to set
enableIvy: trueandcompilationMode: 'partial'....Please delete and rebuild the package with Ivy partial compilationinside your error message refers to this compilation mode.compilationModeSpecifies the compilation mode to use. The following modes are available:
'full': generates fully AOT-compiled code according to the version of Angular that is currently being used.'partial': generates code in a stable, but intermediate form suitable for a published library.The default value is
'full'.JoostK commentedon Jun 9, 2021
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 :)
SuperITMan commentedon Jun 9, 2021
@NiklasPor @JoostK
Thanks for your quick answers! 😃
You're right, I missed the
"compilationMode": "partial"part for libraries. With this option, the "prepublishOnly" is no longer present 👍angular-automatic-lock-bot commentedon Jul 10, 2021
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.