angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

CSS Problem on --prod build

Open omahjoub opened this issue 9 years ago • 62 comments

Versions

Angular CLI: 1.5.3
Node: 9.2.0
OS: linux x64
Angular: 5.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.3
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.36
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.3
@schematics/angular: 0.1.5
typescript: 2.4.2
webpack: 3.8.1

Repro steps

  • Step 1 :
ng serve

capture d ecran de 2017-11-21 19-23-37

capture d ecran de 2017-11-21 19-24-35

I have also a masonry layout that is good.

  • Step 2 :
ng serve --prod

capture d ecran de 2017-11-21 19-36-30

capture d ecran de 2017-11-21 19-37-04

My Masonry layout is also broken (hard to demonstrate sorry!) but i think all is related !

Observed behavior

- My progress bar turns blue!
- My masonry layout is broken!
- No errors anywhere(cli console, navigator console...) but the css is broken with a prod build!

Desired behavior

- My progress bar stays pink!
- My masonry layout stays good!
- Or At least log an error somewhere

Mention any other details that might be useful (optional)

- The --prod build is broking somthing in the css.
- I observed this since angular cli 1.5.0
- All was good with angular cli 1.4.9

omahjoub avatar Nov 21 '17 18:11 omahjoub

This is still and issue in Angular 5 & Angular CLI 1.7.3 --extract-css=false fixes the issue.

lafama avatar Mar 22 '18 09:03 lafama

Just encountered this. Bump, fix please.

worthy7 avatar Apr 06 '18 06:04 worthy7

Not directly related but in case someone lands here and has a similar issue:

I also had an issue where CSS was wrong when compiled with AOT and CLI > 1.6.3 However, my issue was related to :host-context and solved by @bgotink brilliant comment on https://github.com/angular/angular/issues/19199

TL:DR one must not combine multiple css selectors inside " :host-context(.selector-one .selector-two) {} " instead write it as " .selector-one .selector-two :host-context {} "

uluzox avatar Apr 06 '18 07:04 uluzox

@lafama --extract-css=true/false did not fix it for me, I tried various commands and the one that made a difference was --aot This is some how causing a messup. So my current production command will have to be: ng serve --prod --aot=false

worthy7 avatar Apr 06 '18 08:04 worthy7

Not sure if it's the same issue, but in case this helps someone...

I noticed broken/missing CSS when I added --prod flag. After trying various suggestions in this thread I found a work around by using ng build --prod --aot=false, but a deeper investigation revealed that ng build --prod was displaying warnings (not errors) in console in the form of WARNING .......... at 6170:16. Ignoring. These were difficult for me to find in my source code without the filenames and line number, but eventually after resolving them build --prod seemed to work like a charm.

I guess the AOT compiler just throws out the CSS immediately after whatever it deems "invalid" which is confusing because it results in different (broken) CSS to the dev build, and without any errors, and the warning messages are not very helpful troubleshooting.

webdevan avatar Jun 26 '18 15:06 webdevan

I agree with @webdevan, my CSS was working fine when running locally, but then vanished when running a --prod build. For me, the solution was to look at the CSS which had been removed, figure out why it was invalid, and correct it.

In my case, I was including alpha transparency in hex format color codes which isn't very widely supported. Changing it to rgba seemed to resolve the issue.

I saw no errors or warnings when building my application, the CSS was just missing.

simon-lock avatar Jun 28 '18 14:06 simon-lock

Guys come on. Fix this please! Its been almost an year since the issue was open.

nzhul avatar Jul 05 '18 20:07 nzhul

I'm using Angular: 6.0.0, I've same problem too.

In my scenario, I've a global style.css which contains this line @import "~@angular/material/prebuilt-themes/indigo-pink.css";

Additionally ng serve --extract-css=false is not working anymore. It says Unknown option: '--extractCss'

> ng --version

Angular CLI: 6.0.0
Node: 8.11.3
OS: darwin x64
Angular: 6.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, http, language-service, material, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

sadedil avatar Jul 07 '18 05:07 sadedil

Hi, for angular 6 the option has been moved to the angular.json file "configurations": { "production": { "extractCss": false,

lafama avatar Jul 18 '18 03:07 lafama

On Angular 1.7.4, --extract-css=false was not working. Downgraded to 1.6.3 and production bug disappeared.

csgchristian avatar Jul 30 '18 15:07 csgchristian

Same problem with angular 6 using webpack

nimatrazmjo avatar Aug 08 '18 10:08 nimatrazmjo

Same here. Although "configurations": { "production": { "extractCss": false, still works on angular-cli 6.1.1, I'm wondering when this bug will get fixed.

FinalVersion avatar Aug 20 '18 01:08 FinalVersion

This is a still present and odd bug, seemingly random elements of CSS being thrown out. I edited my missing CSS (which was valid and not throwing errors) so that it was on a single line. This fixed the problem. Why this fixed the problem I have no idea, I don't even know why I tried it.

simon-co avatar Aug 26 '18 17:08 simon-co

I'm sorry, but we can't reproduce the problem following the instructions you provided. Remember that we have a large number of issues to resolve, and have only a limited amount of time to reproduce your issue. Short, explicit instructions make it much more likely we'll be able to reproduce the problem so we can fix it.

If the problem persists, please open a new issue following our submission guidelines.

A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

alan-agius4 avatar Sep 03 '18 06:09 alan-agius4

Workaround fix: i have extracted scss code which has problem on component's scss. Then have pasted it to /src/styles.scss file. It worked.

serkon avatar Sep 08 '18 15:09 serkon

Having the same problems as pretty much everyone above with my ng build --prod stripping away necessary SCSS styles for my app rendering it looking half-baked. Running Angular 6.1 and using @imports on the /src/styles.scss file for all of my global styles, all styles rendering fine without any errors when serving locally for dev. I used the workaround from @webdevan to build without AOT: ng build --prod --aot=false which solves my problem for now. Would like to use AOT on my ng builds though.

nthompson777 avatar Sep 26 '18 20:09 nthompson777

I think this the same issue as #9475 What do you need to repro this?

Try using bootstrap in scss and 2 custom css file. Import the first css - Update the primary color to pink then booststrap scss then the 2nd css - Update the primary color to Blakc

Check the final output of the primary color in development mode (ng serve) Then build ng --build.

You will see that the output is not the same.

------------------------------------------ ng --version ----------------- Angular CLI: 6.1.5 Node: 8.11.3 OS: win32 x64 Angular: 6.1.9 ... animations, common, compiler, core, forms, http ... language-service, platform-browser, platform-browser-dynamic ... router

Package Version

@angular-devkit/architect 0.7.5 @angular-devkit/build-angular 0.7.5 @angular-devkit/build-optimizer 0.7.5 @angular-devkit/build-webpack 0.7.5 @angular-devkit/core 0.7.5 @angular-devkit/schematics 0.7.5 @angular/cdk 6.4.7 @angular/cli 6.1.5 @angular/compiler-cli 6.1.7 @angular/material 6.4.7 @ngtools/webpack 6.1.5 @schematics/angular 0.7.5 @schematics/update 0.7.5 rxjs 6.3.3 typescript 2.9.2 webpack 4.9.2

elvince avatar Sep 28 '18 09:09 elvince

Seems that the workaround at this point is to include all your global styles in src/styles.scss rather than builder options in angular.json.

draconis0318 avatar Dec 20 '18 22:12 draconis0318

Why is the issue closed? The bug still persists in Angular 7, like seriously, it's about time to address it.

DrYurii avatar Feb 22 '19 15:02 DrYurii

There is a similar problem to reproduce. NG-ZORRO/ng-zorro-antd/issues/2980

Sioxas avatar Feb 27 '19 12:02 Sioxas