Error with build --prod & templates since angular/cli 1.0
Bug Report or Feature Request (mark with an x)
- [x] bug report
- [ ] feature request
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 OK
ng build --prod is KO since morning after update to angular/cli 1.0
I have one class Field with attributes :
export class Field {
key: string;
type: string;
label: string;
order: number;
fields: Array<Field>;
validators: FormValidators;
attributes: Attributes;
}
And this :
export class Attributes {
canBeCreated: boolean; // Apparait dans le formulaire de création
canBeEdited: boolean; // Apparait dans le formulaire de modification
canBeFiltered: boolean; // Apparait dans les filtres
canBeSorted: boolean; // Permet le tri sur la colonne
isInList: boolean; // Apparait dans la liste
isInDetail: boolean; // Apparait dans le détail
placeholder: string; // Texte qui apparait quand le champ est vide lors de la création ou modification
constructor (attr: Attributes) {
this.canBeCreated = attr && attr.canBeCreated ? attr.canBeCreated : true;
this.canBeEdited = attr && attr.canBeEdited ? attr.canBeEdited : true;
this.canBeFiltered = attr && attr.canBeFiltered ? attr.canBeFiltered : true;
this.canBeSorted = attr && attr.canBeSorted ? attr.canBeSorted : true;
this.isInList = attr && attr.isInList ? attr.isInList : true;
this.isInDetail = attr && attr.isInDetail ? attr.isInDetail : true;
this.placeholder = attr && attr.placeholder ? attr.placeholder : '';
}
}
export class CheckboxAttributes extends Attributes {
options: Array<{label: string, value: string}>; // Liste des valeurs possibles de les checkbox
isBinary: boolean; // Choix true/false ou multiple
constructor(attr: CheckboxAttributes) {
super(attr);
this.options = attr && attr.options ? attr.options : null;
this.isBinary = attr && attr.isBinary ? attr.isBinary : false;
}
}
In my component checkbox.component.html :
<div *ngIf="!field.attributes.isBinary">
.....
</div>
The log given by the failure.
ERROR in C:/Users/LAPASSAL/Projects/marty/src/$$_gendir/app/generic/components/checkbox-input/checkbox-input.component.ngfactory.ts (377,66): Property 'isBinary' does not exist on type 'Attributes'.
C:/Users/LAPASSAL/Projects/marty/src/$$_gendir/app/generic/components/checkbox-input/checkbox-input.component.ngfactory.ts (380,61): Property 'isBinary' does not exist on type 'Attributes'.
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
Hi, there's literally no isBinary property for the Attributes class. So it's normal that this fails because your are checking boolean value of something undefined.
but my field.attributes can a Attributes or a CheckboxAttributes
it is dynamic
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 /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/button/mdl-button.component.ngfactory.ts (1,1): 'l' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/button/mdl-button.component.d.ts.MdlButtonComponent_Host.html (2,1): '$event' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/card/mdl-card.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/checkbox/mdl-checkbox.component.d.ts.MdlCheckboxComponent_Host.html (2,1): '$event' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/chips/mdl-chip.component.d.ts.MdlChipComponent.html (5,5): '$event' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/dialog-outlet/mdl-dialog-outlet.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/dialog-outlet/mdl-dialog-outlet.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/icon/mdl-icon.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
/home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/list/mdl-list.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/icon-toggle/mdl-icon-toggle.component.d.ts.MdlIconToggleComponent_Host.html (2,1): '$event' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/radio/mdl-radio.component.d.ts.MdlRadioComponent_Host.html (2,1): '$event' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/snackbar/mdl-snackbar.service.d.ts.MdlSnackbarComponent.html (5,7): '$event' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/switch/mdl-switch.component.d.ts.MdlSwitchComponent_Host.html (2,1): '$event' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/table/mdl-table.component.d.ts.MdlTableComponent.html (7,18): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/table/mdl-table.component.d.ts.MdlSelectableTableComponent.html (7,18): '$event' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/menu/mdl-menu-item.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout.component.d.ts.MdlLayoutComponent.html (13,9): '$event' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent.html (11,15): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent.html (16,15): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent.html (6,12): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/layout/mdl-layout-header.component.d.ts.MdlLayoutHeaderComponent_Host.html (2,1): '$event' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-drawer.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-content.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-header-row.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-title.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/layout/mdl-layout-spacer.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/tabs/mdl-tab-panel.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/tabs/mdl-tabs.component.d.ts.MdlTabsComponent.html (5,9): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/tabs/mdl-tabs.component.d.ts.MdlTabsComponent.html (12,9): '$event' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/textfield/mdl-textfield.component.d.ts.MdlTextFieldComponent.html (51,7): '$event' is declared but never used.
ERROR in /home/hugo/pix4d/spa/src/$$_gendir/node_modules/@angular-mdl/core/components/dialog-outlet/mdl-backdrop-overlay.component.ngfactory.ts (1,1): 'l' is declared but never used.
ERROR in ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/dialog/mdl-simple-dialog.component.d.ts.MdlSimpleDialogComponent.html (8,9): '$event' is declared but never used.
ng:///home/hugo/pix4d/spa/node_modules/@angular-mdl/core/components/dialog/mdl-simple-dialog.component.d.ts.MdlSimpleDialogComponent_Host.html (2,1): '$event' is declared but never used.

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) using ng build is ok but ng build -prod not ok
AOT (which is enabled via --prod) requires that any property/field/function accessed from within a template be public. This is an Angular restriction. Previously this would only be represented as either a runtime error or unexpected behavior (depending on the usage).
ng build -prod (work fine)
export class AppComponent {
title = 'app works!';
}
but if I use private variable
export class AppComponent {
private title = 'app works!';
}
error happens ERROR in /Users/ARM/Desktop/kibito-ang4/src/$$_gendir/app/app.component.ngfactory.ts (1,1): Property 'title' is private and only accessible within class 'AppComponent'.
Does that mean we have to change all private variable to public variable ?
@clydin
@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 https://github.com/angular/angular-cli/pull/5601.
This can be reproduced in a brand new project by doing the following change (different from original issue but same root cause):
export class AppComponent {
private title = 'app works!';
}
ERROR in D:/sandbox/experimental-proj/src/$$_gendir/app/app.component.ngfactory.ts (1,1): Property 'title' is private and only accessible within class 'AppComponent'.
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:
npm install --save-dev @ngtools/[email protected]
rm -rf node_modules/\@angular/cli/node_modules/\@ngtools/webpack/
This is not optimal and does not carry over on reinstalls.
EDIT: a better workaround is to use @angular/[email protected] instead, as it carries over reinstalls and there isn't a big difference between the two versions.
I just compiled ng build --prod --aot successfully with Angular 1.0 (release) and AngularCLI 1.0.0-rc.2. Works just fine. But AngularCLI 1.0 (release) can't compile same code. So it's not the Angular issue.
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 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 [email protected] 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 https://github.com/angular/angular-cli/issues/5623#issuecomment-289075279, 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 [email protected] 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 https://github.com/angular/angular-cli/issues/5623#issuecomment-289077974, 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: https://github.com/angular/angular-cli/issues/5623#issuecomment-289075279
What was happening was that the CLI on older versions was always swallowing these errors.