Atul Acharya
Atul Acharya

Reputation: 507

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

I am working on an angular app.

Using

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

Upvotes: 11

Views: 26371

Answers (2)

Antoine Clavijo
Antoine Clavijo

Reputation: 1305

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.

Upvotes: 38

Noémi Salaün
Noémi Salaün

Reputation: 5036

The --prod flag activate many optimization flag. One of them is --aot for Ahead Of Time compilation. Your component templates are compiled during the build, so TypeScript can detect more issue in your code. You can compile in dev mode but still activate the --aot flag if you want to see this error before building for prod.

From the official compiler documentation

Detect template errors earlier

The AOT compiler detects and reports template binding errors during the build step before users can see them.

Upvotes: 18

Related Questions