Property is private and only accessible within class
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@angular/cli: 1.0.0 node: 6.9.5 os: linux 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/material: 2.0.0-beta.2 @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 -prod
The log given by the failure.
ERROR in /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4028,18): Property '_sidenav' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4030,18): Property '_infoSidenav' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4032,18): Property '_owlCarousel' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4034,18): Property '_tree' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4036,18): Property '_ol3Map' is private and only accessible within class 'AppComponent'. /home/u/maps-msda-ng2/src/$$_gendir/app/app.component.ngfactory.ts (4524,22): Property '_extendedSearchAccordion' is private and only accessible within class 'AppComponent'.
Mention any other details that might be useful.
ng serve works
link to the code of the component: http://pastebin.com/p8EFtbFB
@iamonuwa Could you please elaborate on how to do that?
running this command to deploy the app will fix it.. ng build --env=prod
found the solution in github
ng build --env=prod worked. Seems ng build --env=prod and ng build --prod are not same.
@deeptiProjects can you describe the difference
@deeptiProjects @arun31786 with ng build --env=prod you do not achieve AOT compilation, for more details see docs: https://github.com/angular/angular-cli/wiki/build#build-targets-and-environment-files
Original "error" reported is not an error, but normal restriction of AOT at least for versions 2, 4, 5. The variable used in the template needs to be declared as "public". Template is treated as a separate Typescript class.
ng build -prod --aot=false
@arun31786 Documentation claims those commands are the same:
# these are equivalent
ng build --target=production --environment=prod
ng build --prod --env=prod
ng build --prod
Try ng build --prod aot false
I have also the same issue!
Same issue here after angular 5 update. I don't want to make all properties en methods public.
These links might helpful: https://angular-2-training-book.rangle.io/handout/aot/aot_limitations.html https://github.com/rangle/angular-2-aot-sandbox
I used angular 2.4.10 , angular-cli 1.0.6 ,typescript 2.2.1 I got this error when i upgrade angular to 2.4.10 from 2.3.1 and cli to 1.0.6 from 1.0.0-rc.4 it serves but cant build for prod with aot i have solved to build without aot -> "ng build --prod --aot=false"
I used angular 5.0.5 and cli 1.5.5 have same problem too. Many error:
- Property ... does not exist on type
- Property ... is private and only accessible within class
So, we can't use "ng build --prod" ?
+1
Property 'nav' (nav is a private instance of a component in constructor) is private and only accessible within class.
Angular 5.1+ CLI: 1.6.3
This errormsg appears when ng build --prod
I have several instances of the same injected variable and it's private in some places and public in others, and it's used in some templates as a private variable, yet one module is complaining that it's private, and the rest aren't.
+1 it happens with protected as well. I'm not able to make right sense from those keywords then!
I am using Angular 5 and having the same issue when deploying Jenkins build. The annoying part is it works locally but not when I make a build
Changing to public when used in templates worked for me. Not sure why only one module complained though.
Same, cannot make a build for production, this is quite annoying. Angular 6.0.7 Angular CLI : 6.0.8 Everything is working fine in development and for a regular build. POO but forced to make everything public ?
I had the same issue. What I understood, the most correct way is to define your variables as public when planning on using them in a template.
With that said I ended up having to change 1000+ properties in my components. In order to do that efficiently I created this python-script: https://github.com/marcus13371337/angular-aot-fixer
Hope that can help some others to speed up the migration from private properties to public properties in your projects!