Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inconsistency in 'ng build' vs 'ng build --prod'

I am working on an angular app.

Using

  • Angular 5.2.5
  • Angular CLI 1.6.8

When I executed command

ng build

I did not get any error, but when I tried production build

ng build --prod

I got error

Property 'someProperty' is private and only accessible within class 'SomeComponent'.

Reported error was correct, and I fixed it.

The question is Why dev build did not report this?. Is that a defect in angular-cli OR am I missing something?

Thanks

like image 629
Atul Acharya Avatar asked Mar 02 '18 08:03

Atul Acharya


1 Answers

ng build --prod compile with Ahead of time compilation. To pass the aot compilation you need to pass your property someProperty to public. See this issue on angular-cli

Just for reminder the differences between ng build and ng build --prod:

# these are equivalent
ng build --target=production --environment=prod
ng build --prod --env=prod
ng build --prod
# and so are these
ng build --target=development --environment=dev
ng build --dev --e=dev
ng build --dev
ng build

And the default option lunch of --dev and --prod flags:

Flag                 --dev    --prod
--aot                false    true
--environment        dev      prod
--output-hashing     media    all
--sourcemaps         true     false
--extract-css        false    true
--named-chunks       true     false
--build-optimizer    false    true with AOT and Angular 5

Documentation ng build

Hope it's help.

like image 144
Antoine Clavijo Avatar answered Oct 19 '22 08:10

Antoine Clavijo