Search code examples
angular2-cli

Angular 2 Cli Issue while ng build --prod but if I use ng build only then it work's fine but size of app is too large


I am having this issue while ng build --prod. it works fine ng build but give issue in ng build --prod

ERROR in Expected 'styles' to be an array of strings.

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\Projects\simplifyng2\src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts

Solution

  • Based on the error message, I can assume that you forgot to use square brackets in the styles property either in .angular-cli.json or in one of your components.

    When you run ng build --prod, it performs AOT by default. As per my experience, AOT compiler catches more errors than JiT. Try this experiment - turn off the AoT during the prod build:

    ng build -prod -aot=false
    

    Most likely you won't see any errors.