-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Custom decorators are stripped when using the AoT build flag #2799
Comments
I'd like to see this resolved. AoT is great, but custom decorators will be important in the future as more and more third party modules take advantage of the stable API, unlike the current crop out there which tend to be developed on the RCs. The problem is |
The custom webpack loader is what is doing the actual decorator removal: https://github.com/angular/angular-cli/blob/master/packages/webpack/src/loader.ts#L18 |
@MikeRyan52 thanks for raising this (and all the hard work on ngrx + effects to begin with). I agree that is critical to be resolved. I guess the main reason, I have not hit it directly, yet, is that beta.17 with aot and lazy-loading was the initial constraint hitting. I know, everyone on the angular-cli team is working hard, but the resolution of this issue should be most welcome. |
We have the same thing with |
Previous behavior was to remove all decorators from a source file when using the @ngtools/webpack loader. This had the side effect of removing any third party decorators, potentially breaking apps silently when using the aot produciton flag. This skips the decorator removal process until a better way can be determined to remove Angular-specific decorators. Closes angular#2799
I think I saw this same failure mode in an example program that made use of a simple custom decorator. Unfortunately that code is long gone, I ascribed it to programmer error at the time - but once this issue is fixed I will certainly try again. |
I see the exact same behavior in my application. I have a class with some method decorators:
When building the application with the AOT option, the decorator is being stripped out by the CLI but the build is a success. Then i run into runtime issues because of the decorator not being applied. The decorators are then also dropped because they are unused.
We will have to wait for a proper fix as described here: #2881 |
So I understand the tradeoff between tree shaking and allowing custom decorators. However my feeling is that if I have to choose between an optimization (tree shaking) vs. correctness in the code output (not stripping all decorators) I would be inclined to choose correctness first, while I work on re-enabling the optimization afterwards. This is putting a few people in a fairly awkward position... |
Sorry, I haven't commented on this issue and should have. We will support custom decorators, this is a real issue, but the solution isn't as easy as it seems. There are a lot of performance implications, and build time is an important factor. The current solution we're considering: dev build will not remove any decorators and as such will not tree shake properly. That's okay, it's dev. Prod builds will only remove decorators that are marked as annotations using tsickle. The prod builds will be slower (as slow as today), while the dev builds (where RTT is much more important) will be larger. Again, this is what's being considered. The final solution might not be the same. For the time being I'll keep the code as is, but switching to tsickle will happen real soon. |
ok thanks @hansl |
This issue should be top priority as it makes larger apps (which usually have some custom decorators in place) impossible to compile ahead of time. And the larger the app is (the more components it has), the longer time the JIT takes. This results in terrible performance and makes angular2 quite problematic to be used in production. I would really appreciate any short-term fix. While tree shaking is nice (and I understand the reasons for decorator stripping), I would gladly accept not having it for some time if that means I am able to do AoT at the moment. |
I couldn't agree more with @xaralis. We have a large application that actually uses a lot of custom decorators. We also have terrible performance using the JIT and are in the real need of AoT but since the decorators are stripped away we cannot use it... I don't get how this issue only can have priority 2, it should definitely have higher priority. |
While we're waiting for fix, I've added temporary version of @ngtools/webpack that doesn't touch decorators: https://github.com/Polvista/ngtools-webpack-keep-decorators. Usage is pretty easy: |
How do I change because there is no webpack config in cli? |
@sithwin it won't help if you use angular-cli to perform AOT compilation. However, decorators will work if you compile with webpack + ngtools-webpack-keep-decorators. It's just drop in replacement for @ngtools/webpack. |
Any updates on this would be very much appreciated, I'll try @maxime1992 fork in the meantime and/or try ngc to do my AoT builds instead. Thanks |
Nice, thanks for the update @maxime1992 |
There is a new version of the cli ( |
@nirgn975 yes, a temporary fix via PR #3583 is in while they implement a better permanent solution. |
@Splaktar Great, thanks! |
Just tried again with beta.24 and this appears to be fixed? |
Temporary fix. All decorators are kept but file sizes are now larger |
ok cool, thanks. |
Decorators are no longer being stripped. |
Aren't they stripped again? I'm using custom decorator and it's being stripped on latest version of @ngtools/webpack |
@KKrisu this is weird. Which version of cli / angular are you using ? I don't have that problem (and I'm using ngrx/effects, custom decorators were stripped before but not anymore). |
@KKrisu I suggest using https://github.com/shlomiassaf/ngc-webpack instead of @ngtools/webpack, it seems way much more mature/stable (at least in present). |
Hey, @maxime1992 I'm on @ngtools/webpack@1.3.0 export function Embeddable(key: string) {
return function(componentClass: Function) {
// our custom code
}
} then in components import { Embeddable } from '...';
@Embeddable('link')
@Component({
... @xaralis thank you, I will consider this alternative if we have more problems, currently, this is the only one with the decorator. |
Angular cli removes standart decorators. That does't worked at same times AOT and Jit. |
@Brocco Just wonder when you say decorators are not striped, do you have fix number? It seems it stills removes them. I see in the code (ngtools):
Is this is the solution ? Thank you, |
Any news about this? As soon as i compile it with --prod my decorators are removed. Can i keep them? |
Even standard decorators are removed. |
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. |
OS?
Mac OSX Sierra
Versions.
Repro steps.
--aot
flag@Effect()
decorator from @ngrx/effects has been stripped from the classesThe log given by the failure.
No errors are thrown
The text was updated successfully, but these errors were encountered: