-
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
Error with build --prod & templates since angular/cli 1.0 #5623
Comments
Hi, there's literally no |
but my |
We are getting hundreds of errors in our AoT build too after the upgrade. Even lots of errors in external libraries that worked just fine in all the RCs (both of Angular and the CLI):
|
ERROR in /Users/ARM/Desktop/kibito_web/src/$$_gendir/app/admin/member/member-add/member-add.component.ngfactory.ts (1627,45): Property 'member_name' is private and only accessible within class 'MemberAddComponent'. hundreds of errors in our AoT happen after upgrade cli 1.0.0 (from beta 32) |
AOT (which is enabled via |
ng build -prod (work fine)
but if I use private variable
error happens Does that mean we have to change all private variable to public variable ? |
@rainstormza unfortunately yes. You need to update all variables used in the template as public. |
@clydin all variables used in template :) |
Yes. I know this is unfortunate for those with large applications and it seems counter-intuitive from an encapsulation perspective, but Angular's AOT mode requires it and these errors were actually always present just not reported. |
@clydin not to complain, but could have informed the developer such as "Using private template variables is deprecated and will be removed in final release. Please use public" |
@demirk4n It has been the case for a long time, it's just that the CLI was not showing the errors reported by the Angular compiler when building with AoT (that was a bug). It has been fixed just before the 1.0 release. |
@clydin no, it's not Angular restriction. rc5 was compiled successfully with same code (and without errors in runtime) and 1.0 can't be compiled. |
I think this has been there for a while with the AOT compiler itself but as @clydin said we were not reporting it in the CLI, and that changed in #5601. This can be reproduced in a brand new project by doing the following change (different from original issue but same root cause):
I agree that this is very bothersome for existing projects trying to upgrade. The only workaround I found to bypass this for now is doing the following:
This is not optimal and does not carry over on reinstalls. EDIT: a better workaround is to use |
I just compiled |
By "AOT compiler" I meant the
What was happening was that the CLI on older versions was always swallowing these errors. |
Could you please just display them but don't break compilation?
…On Fri, 24 Mar 2017 at 17:39, Filipe Silva ***@***.***> wrote:
By "AOT compiler" I meant the ngc binary. If you try using it directly on
your project you will get the same error (warning: this will generate
.ngfactory.ts files and others):
$ $(npm bin)/ngc src/tsconfig.app.json
Error at D:/sandbox/experimental-proj/src/app/app.component.ngfactory.ts:31:30: Property 'title' is private and only accessible within class 'AppComponent'.
What was happening was the the CLI on older versions was always swallowing
these errors.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5623 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAgIEP4C3taf3huAHiPGrAlNsMboVhphks5ro_GtgaJpZM4MoHrW>
.
|
They are actual errors. Angular's AOT mode requires public access; it is not a CLI limitation. |
looks like you are ignoring what I write. Ok.
…On Fri, 24 Mar 2017 at 17:48, clydin ***@***.***> wrote:
They are actual errors. Angular's AOT mode requires public access; it is
not a CLI limitation.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5623 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAgIELq93bUnEhzDjLXXCUsBH5GcMv-Dks5ro_PqgaJpZM4MoHrW>
.
|
@clydin I'm not sure I understand. You say they are "actual errors", but I'm confused as to why they were not "actual errors" yesterday with rc.4? I got several warnings but the app ran fine. Today it won't even compile. Was my app missing functionality yesterday that I'm not aware of? And will that be restored once I sift through my code and switch every template-accessed variable to public? |
@billdwhite see my comment above: #5623 (comment)
|
Thanks @filipesilva. I now understand what caused it, but why the requirement? Seems like template variables being private (or at least protected) makes more sense than exposing everything the template is using within it's own component to the outside world......just my view on it. |
Issue is not only with private/public variables, please don't convert it to simple private to public replacement. There are also errors like "value ISomeType can't be assigned to boolean" (just compiler's fault) or when variable is declared in template (#var) and compiler complains that there is no such field in component. |
@billdwhite I am not the right person to ask about the requirement. It is an AOT Compiler requirement, and the CLI just uses an implementation of it via Issues with the AOT compiler per se are better suited for https://github.com/angular/angular as that's the right repository. It was a CLI bug that we were ignoring that whole class of errors though. And the result is that until now CLI users had AOT errors in their projects that we weren't showing, and so they never had a chance to fix them. Like @e-oz said, it's not just private/public properties, it's other AOT errors as well. Now all these errors appear all at once which is hard to deal with. EDIT: this is the original issue that needed fixing: #4538 |
We always swallowed TS errors on templates, and now we report them as errors. I'm looking into reporting warnings as warnings instead, which seems to be the case here. |
@istiti if you are doing long term jobs you need to keep your libraries stable enough and plan migrations accordingly.I know a lot of shops using AngularJS - not even 2.x just for the sake of stability. You can't expect any software to be %100 bug free on day one. Furthermore you can upgrade your global @angular/cli to 1.0 and use rc.4 locally. |
@demirk4n u r totally right, i just expect from cli to write in even ONE LINE in console that im using private in template even if it compile aot (i assum its beta but not serious at all) Cheers |
I understand the restrictions AOT places on the angular team, but this use case happens often when managing authenticated state: In this case, some
Reference: https://auth0.com/blog/angular-2-authentication/ The angular docs them self reference the use of an Directly using service methods or properties in templates, especially when combined with the |
@ojourmel in your example you are using publicly accessed method, not private field :) I mean, in case of services it's easy to predict what property will be used outside to make this field public. But yes, maybe my initial statement was too broad :) |
@filipesilva @hansl it's good to show the errors. But we need to address it in changelog as breaking change. Developers like myself were developing production apps find this very disturbing. Since we need to change almost all the source files. It would be better to address it in breaking change, so that we won't get panicked. |
@e-oz In this way, AOT will fail to allow me to use the I have done up a very small project to demo this issue: https://github.com/ojourmel/demoAOTPrivateIssues |
Thanks guys for all comments above. I am Angular2 crazy follower and recommended ng2 to client. :) also upgrading ng versions immediately when new version is released. But Today I got a lots of errors while building product and it make all of us frightened. :( I will try to migrate all private properties to public but I hopes this issue would be solved soon from respected angular team :) |
thanks to team for this breakin change |
so, everybody is complaining about these problems, but nobody provides a solution? what's the best practice here?
thanks |
it's simple, aot require all members you use outisde your class be public. But this cli console, doesn't tell us before relase! Team forget people using cli since a while with big project, response: we have to KNOW that for aot all members are public ! I can say too:
maybe now cli is good, but before release cli was 💩 |
Is there a tool to check this kind of error? I remember |
I'm also looking for a best practice here.
This aligns pretty well with common encapsulation conventions with the only downside to write a little more code. |
Thanks for your comment @basst314. But Too many codes should be modified. That is not good option.
Here is my |
@basst314 getters/setters are fine if there's a business requirement to modify underlying private property. Apart from that, just for template binding - get/set creation is somewhat overkill.
|
What would you suggest @demirk4n ? |
You seems don't know how template and class are connected. For me there is sens to have it punlic only reclamation goes to cli that doesn't inform us with error in console ! |
@basst314 I'd just use public properties for basic template stuff and getter/setters to wrap around a more complex business logic for a private property. One can hope, maybe in the next iteration of ES Microsoft may surprise us with a C# get/set functionality :)
which will be equal to
|
It seems that Angular 4.0 is not able to recognize the local variable inside ngFor loop.
In UPDATE: So, the problem could be related to |
@thaihacong i think these needs to be as directives. |
@harilal |
trackBy is now function! how you use trackBy is bad. please check docs it's function that retunr id |
I'm locking this discussion down. The original issue is being worked on and the discussion is getting a bit out of hand here. |
@alapasset Regarding your original issue: The following code in Typescript will not compile: interface A {
aValue: number;
}
interface B {
aValue: number;
bValue: string;
}
function a(aOrB: A | B): string {
const x = aOrB.aValue; // Valid. aValue is part of both interfaces.
const y = aOrB.bValue; // ERROR. bValue is not part of A.
}
a({ aValue: 1 }); I think this comes from a misunderstanding of what the You need to change your typings to reflect the code, or typecast it if possible. I'm going to close this issue. I have a PR to move warnings in templates as warnings, but it's not a fix for this issue. |
#5698 fixed typescript messages and warnings to not be considered errors. Please note this will not remove errors from your templates from being reported. |
Previously, we were reporting all diagnostics as errors. Now only Typescript errors will be reported as real errors to webpack. Messages and warnings will be warnings. Fixes angular#5623
Bug Report or Feature Request (mark with an
x
)Versions.
$ ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ | | __ _ _ __ / | | | |
/ ? \ | ' \ / _
| | | | |/ _
| '| | | | | | |/ ___ | | | | (| | || | | (| | | | || | | |
// __| ||_, |_,||_,|| _|||
|___/
@angular/cli: 1.0.0
node: 6.9.2
os: win32 x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0
@angular/compiler-cli: 2.4.10
Repro steps.
ng build
all is OKng build --prod
is KO since morning after update to angular/cli 1.0I have one class Field with attributes :
And this :
In my component checkbox.component.html :
The log given by the failure.
In typescript can I cast the object type to CheckboxAttributes with
(this.field.attributes as CheckboxAttributes).isBinary ? false : []
but how can I do this in template? Any idea ?Thx
The text was updated successfully, but these errors were encountered: