angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

AOT seems to be enabled by default in beta.22 ?

Open ritz078 opened this issue 9 years ago • 57 comments

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

El Capitan

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.22 node: 6.6.0 os: darwin x64

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

run ng serve

The log given by the failure.

Normally this include a stack trace and some more information.

10% building modules 2/2 modules 0 active(node:14509) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in /Users/ritz078/projects/housing-assist/src/app/app.module.ts, resolving symbol AppModule in /Users/ritz078/projects/housing-assist/src/app/a 20% building modules 86/86 modules 

Mention any other details that might be useful.


Thanks! We'll be in touch soon.

ritz078 avatar Dec 03 '16 15:12 ritz078

It looks like aot is enabled by default but I'cant even disable it.

kucharzyk avatar Dec 03 '16 15:12 kucharzyk

This has already been reported in #3354.

sgybas avatar Dec 03 '16 15:12 sgybas

These are the approximately gzipped production payload for my application:

CLI beta 21/Angular 2.2.1 without AoT. main.bundle: 260kb, 0.chunk: 20kb...
CLI beta 21/Angular 2.2.1 with AoT. main.bundle: 200kb, 0.chunk: 50kb... CLI beta 22/Angular 2.2.3 AoT only. main.bundle. 70kb, vendor 130kb. 0.chunk: 50kb...

Basically with AoT, the main/vendor bundle reduced by about 20%, but all the other lazy/pre-loaded chunks increased, some by more than 100%. I compared the chunk's source and found that with AoT, the size increase seem to came from very many pre-compiled html js code, such as

this._text_50 = this.renderer.createText(this._el_49, "Some html text", null), this._text_51 = this.renderer.createText(this._el_47, "\n ", null), this._text_52 = this.renderer.createText(this._el_45, "\n ", null), this._text_53 = this.renderer.createText(this._el_43, "\n ", null), this._text_54 = this.renderer.createText(this._el_0, "\n", null),

where this._el_123 reference a renderer of an html tag. These "\n" code lines basically matches the closing HTML tag. Without AoT, these code would be replaced with plain HTML developers code up.

Is this expected? Are there any work in progress to reduce the pre-compiled code size? Due to this increase, it may not be worth it in certain situation to turn on AoT. Not sure if this should be a CLI issue or an Angular2 framework issue. If so, please advise...

aaronleestic avatar Dec 05 '16 03:12 aaronleestic

I deleted a comment that was obviously against the code of conduct.

hansl avatar Dec 05 '16 19:12 hansl

@ritz078 we don't enable AoT by default, BUT we do generate lazy bundles. The code that analyze your project for lazy routes still uses static analysis to figure out your lazy routes. We had "faulty" code before that was working which we might revert too; it was dumber but in this case it would fix it.

hansl avatar Dec 05 '16 19:12 hansl

We changed the way we analyze lazy routes in the CLI; you now have to use statically analyzable code. This is more solid and also takes into account libraries that include routes and lazy routes. It also means the code needs to be AoT-compatible, even though you're not using AoT to compile it.

The problem here seems to be that you either:

  1. are using function calls that are not "simple" enough for the static analyzer to understand, or
  2. are using a library that doesn't include metadata.json files. This can be figured out by remove libraries and seeing if the code compiles.

For point 1, you should not use function calls or non-const values in metadata. Metadata is supposed to be static and easily parseable.

For point 2, we (the Angular Team) offer best practice guides for library developers to follow, in order to be AoT compatible. Libraries should follow those best practices. If you are (or know) the library author, this page explains how to be AoT compatible for a library: https://angular.io/docs/ts/latest/cookbook/aot-compiler.html

hansl avatar Dec 06 '16 18:12 hansl

It seems that the user experience(in my case ng serve stalling) is not ideal. Also, it seems that ng serve/build is ignore my tsconfig and using declaration: true as I am seeing a lot of these type errors after upgrading to the latest beta: exported variable 'reducers' has or is using name 'Action' from external module

the-destro avatar Dec 06 '16 19:12 the-destro

@hansl I'm not sure to understand, but if we use a non compatible AOT library, we won't be able to use angular-cli (except < beta 22) ?

maxime1992 avatar Dec 06 '16 19:12 maxime1992

@maxime1992 seems so. + there are several new problems like using non-reexported types as return type of methods in exported class...

@the-destro yeah.. with beta.22 i have 1000 errors like this regarding rxjs... and now i dont know how to fix those errors.. do you?

IM so afraid, that this change - you need every library to be AOT compatible, will brake the neck of Angular 2.....

montella1507 avatar Dec 06 '16 20:12 montella1507

Although it is momentarily inconvenient, I think it is a very positive development to see CLI requiring that code and libraries have the bits necessary to work with AOT. This should result in a better sense of urgency among application and library authors to become compatible with AOT.

In the long run, I think this would be even better: for Angular itself to be modified a bit such that JIT imposes as close as possible to the same requirements as AOT.

kylecordes avatar Dec 06 '16 22:12 kylecordes

this will lead to the end of angular, because authors of 3rd party libraries wont invest their time to modify code and build it with ngc.

montella1507 avatar Dec 06 '16 22:12 montella1507

@kylecordes I loved that I could use some older javascript libraries - for example jQuery jsTree, some color picker and so on.. and write simple wrapper for Angular 2. There are lost of non-angular libraries which are really great and up to this moment could be used (with some wrappers) with angular. Now if you cut them out, you end up with just bunch of Angular 2 libraries with very varying quality.

I don't think it is a good idea.

Right now no one is forcing me to use AOT, so I will avoid it as long as possible. But I'm also losing benefits of it - just because you decided to make this huge breaking change in beta.22.

klinki avatar Dec 06 '16 22:12 klinki

@klinki What I described would only affect Angular specific reusable libraries. It would not affect jQuery or any of zillions of other reusable chunks of code which don't have any Angular specific annotations / components / etc. in them. I'm not on the Angular team so I am not among the "you" who put in this change :-) but I think a couple of the messages here overstate the impact. The current situation is basically an accident of history, that the requirements for Angular code compatible with AOT are different than the requirements for angular code compatible with JIT. I suspect in a few more versions we will all have long forgotten that, the requirements will have been brought close enough that JIT is no big deal, routinely use, as the Angular team has had in mind for a long time. It's a big complicated thing, takes a while to accomplish the full vision.

kylecordes avatar Dec 06 '16 22:12 kylecordes

I agree with @kylecords. This won't affect non angular libs and now anything built with the cli will be AOT compliant. I do see that it is causing some pain but I believe it to be a net good.

deebloo avatar Dec 06 '16 22:12 deebloo

I am not even able to build several Anuglar 2 starter packs, because of errors like:

exported variable 'xyz' has or is using name 'Subject' from external module rxjs

which is built-in in angular 2. Thats the thing,.. so i wont talk here about 100 libraries which you have mentioned on your main page angular.io like PrimeNG,, Kendo,.. that ARE NOT ready for AOT.

montella1507 avatar Dec 06 '16 22:12 montella1507

I think it's much more than just momentarily inconvenient. As Angular-CLI devs we will now have to audit every open source component we bring in and ensure that they are AoT-friendly before we can use them, even if we have no interest in making an AoT app. In my experience there will be many components that will never be updated so we'll just have to skip them and try to find something else. I don't think it's the "end of angular" but it's definitely a huge hassle.

bonnici avatar Dec 06 '16 23:12 bonnici

My immediate concern is that #2799 is still open, i.e. the interaction between AOT compilation and custom decorators critical to state management/side-effects solutions in two material libraries is not yet resolved.

For the first time in the beta cycle, I have held off on upgrading, i.e. from beta.21 to beta.22, as it is not self-evident to me whether said issue is exacerbated with the latest release.

So, if someone could shed some light on this particular aspect, I should be most indebted.

tomwanzek avatar Dec 06 '16 23:12 tomwanzek

@deebloo

I do see that it is causing some pain but I believe it to be a net good.

For sure, idealy if everything was AOT compliant it would be nice awesome. But it sounds impossible to have every project AOT compliant. As a developer willing to give the best for my users, I'm ready to make my code AOT compliant. But some devs out here won't do that. Especially 3rd party libs. This brings me to that question :

This won't affect non angular libs

How so ? This is really something I don't understand. What are the boundaries of AOT ? Is only our code required to be AOT compliant or also the libs we use ?

Last thing is, as @tomwanzek said, there's a huge concern of introducing the obligation to have our code AOT compliant when #2799 is still opened : Custom decorators are stripped off. I tried to launch my app yesterday after making it fully AOT compliant, and as I use @ngrx/effects my app was displaying well ... But nothing was happening as most of the work is launched from effect.

I've been sticking with angular-cli since the beginning, even tho there are great starters out there that support AOT, lazy loading, hmr, etc for months.

But I really like the idea behind angular-cli : Having a similar code base for every repo and making a tool common to every devs so it's easier to work on another project.

I loved the decision and (huge) work done when switching from systemjs to webpack. But this time, it feels like this is a big decision with a deep impact on the community (+ existing projects) and we didn't see that coming.

Could it be possible to have an issue opened to discuss that kind of update, even before the work gets started ? I don't know if asking community opinion for big changes is something common in open source world, but it'd probably be great and constructive ! :)

maxime1992 avatar Dec 07 '16 07:12 maxime1992

@maxime1992 totally agree that it is odd to have this change in before having a fix for #2799. when I said it won't affect non angular libs I mean to say that if you are using jquery, moment, or something like that AOT doesn't affect it.

deebloo avatar Dec 07 '16 12:12 deebloo

I think having it enabled by default but able to be disabled should be the mantra going forward with some of these big "flag" type changes. Also, enforcing AOT compliance only makes sense to me if Angular itself did not support JIT. Perhaps they will with Angular 3 that will be the case. If it is, then this seems be best left for a 2.0 version of the cli.

the-destro avatar Dec 07 '16 17:12 the-destro