Angular 4 : Build to prod: Property is private and only accessible within class

Changing to public activatedRoute

You need to make your activatedRoute public. Here's a checklist when building for production with aot. ( Taken from this github project https://github.com/asadsahi/AspNetCoreSpa, though it is applicable to any other angular project.)

AOT - Ahead of time compilation DON'TS

  • Don’t use require statements for your templates or styles, use styleUrls and templateUrls, the angular2-template-loader plugin will change it to require at build time.
  • Don’t use default exports.

  • Don’t use form.controls.controlName, use form.get(‘controlName’)

  • Don’t use control.errors?.someError, use control.hasError(‘someError’)

  • Don’t use functions in your providers, routes or declarations, export a function and then reference that function name Inputs, Outputs, View or Content Child(ren), Hostbindings, and any field you use from the template or annotate for Angular should be public

Keeping activatedRoute private

To keep your activatedRoute private, you can do something like this

theData:any;
constructor (
private sessionService: SessionService,
private router: Router,
private activatedRoute: ActivatedRoute
 ) {
     this.activatedRoute.params.subscribe(
      params => {
        this.theData= params['keyWorking']; 
        //you will bind the theData instead of the activatedROute
      }
    );
}

}

and in your template

<div class="confirmationMessage" *ngIf="theData == 'validateInscription'">
<br>Un lien de confirmation vous a été envoyé sur votre boîte email afin de 
 valider votre compte. Merci.</div>

Please find more detail in Property is private and only accessible within class

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.

You can change all the components variable from private to public. If they are used into your template.

Or you can use ng build -prod --aot=false for building