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

1.7.0 fonts are corrupted after prod build

Open MateEke opened this issue 8 years ago • 64 comments

Versions

Angular CLI: 1.7.0 Node: 8.9.1 OS: win32 x64 Angular: 5.2.5 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

@angular/cli: 1.7.0 @angular-devkit/build-optimizer: 0.3.1 @angular-devkit/core: 0.3.1 @angular-devkit/schematics: 0.3.1 @ngtools/json-schema: 1.2.0 @ngtools/webpack: 1.10.0 @schematics/angular: 0.3.1 @schematics/package-update: 0.3.1 typescript: 2.7.1 webpack: 3.11.0

Repro steps

  • Install @angular/cli: 1.7.0
  • import fontawesome in .angular-cli.json or in styles.scss
  • run ng build --prod

Observed behavior

Failed to decode downloaded font: http://***/fontawesome-webfont.af7ae505a9eed503f8b8.woff2?v=4.7.0 OTS parsing error: invalid version tag

Desired behavior

FontAwesome icons works fine

Mention any other details that might be useful (optional)

With cli 1.6.8 everything is OK

MateEke avatar Feb 16 '18 10:02 MateEke

If anyone is having this issue when using a custom font with Material, the fix is to specify a full CSS font definition string as font-family, including a web-safe font.

$project-typography: mat-typography-config(
-  $font-family:   'Johnston ITC',
+  $font-family:   'Johnston ITC, sans-serif',
   $headline:      mat-typography-level(48px, 48px, 500),
   $title:         mat-typography-level(40px, 40px, 500),
   $subheading-1:  mat-typography-level(32px, 34px, 500),

This fixed the warnings for me.

Ant59 avatar May 29 '18 12:05 Ant59

assets/fonts/iconfont/material-icons.css

@font-face {
  font-family: 'Material Icons';
  font-style: normal;
  font-weight: 400;
  src: url(MaterialIcons-Regular.eot); /* For IE6-8 */
  src: local('Material Icons'),
       local('MaterialIcons-Regular'),
       url(MaterialIcons-Regular.woff2) format('woff2'),
       url(MaterialIcons-Regular.woff) format('woff'),
       url(MaterialIcons-Regular.ttf) format('truetype');
}

.material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;  /* Preferred icon size */
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;

  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;

  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;

  /* Support for IE. */
  font-feature-settings: 'liga';
}

angular.json:

                        "styles": [
...
                            "src/assets/fonts/iconfont/material-icons.css"
                        ],

css:

                        .mat-selected::before {
                            content: "check";
                            font: normal normal normal 14px/1 "Material Icons";
                        }

The builder removes the font-familiy: 'Material Icons' tag from the ::before definition and reports the warnings during the build process

"@angular/cli": "^6.0.1",

ghost avatar Jun 01 '18 14:06 ghost

There is definitely a bug in the optimiser. "optimization": false fixes the issue but it's not the solution. I had two definitions for:

.mat-selected::before {

in the same file so i joined them and changed the css a bit and then it worked:

.mat-option.mat-selected::before {
    color: $primary-one !important;
    font-family: "Material Icons";
    content: "check";
    display: inline-block;
    font: normal normal normal 14px/1 "Material Icons";

ghost avatar Jun 01 '18 14:06 ghost

I noticed a few others in this thread were also using nginx and having this problem, so I ran a few tests. We were getting an 'OTS parsing error: invalid version tag' console error when loading the fonts.

  • I had noticed that after upgrading to Angular CLI 1.7.4, that the app was requesting our font-awesome fonts with ?v=4.7.0 appended to the request. CLI 1.6.8 was not.
  • Copy/paste the full font request was actually returning the index.html page.
  • Looking in our nginx conf, we have the following, which allows a page refresh to work with the Angular router, and not going to a 404 page. (www.example.com/profile would load www.example.com/index.html and then the Angular app would load profile route)
location / {
   try_files $uri$args $uri$args/ /index.html
}
  • Removing this nginx conf section allowed the font-awesome fonts to work again, but page/app reloading no longer worked if you were sitting on a route other than the home/default.
  • I then added the following right above the location / section to catch the font requests and do nothing.
location ~* \.(eot|otf|ttf|woff|woff2)$ { }

Our fonts are now working with CLI 1.7.4 and page refreshes continue to work.

It may not be the fix for everyone, but I believe this nginx conf or a similar conf section is on a lot of Angular/nginx articles/tutorials, so hopefully this will help others having this issue.

escline avatar Jun 04 '18 15:06 escline

Experiencing the same problem with @angular/[email protected]

@escline's fix did not work for us.

Here is our full nginx configuration:

server {  
	listen 80;
	index index.html;

	error_log  /var/log/error.log;
	access_log /var/log/access.log;
	root /opt/app/dist;

	location ~* \.(eot|otf|ttf|woff|woff2)$ { }
	location / {
		try_files $uri$args $uri$args/ $uri/ /index.html =404;
	}
}

If I remove the version tag from the url, the fonts are served correctly.

jurienhamaker avatar Jun 14 '18 10:06 jurienhamaker

I found that font awesome contains a query string parameter for the version (old, defunct cache busting technique). I added $uri $uri/ to my nginx location block.

cmckni3 avatar Jun 21 '18 17:06 cmckni3

I found a solution: Remove the url version there in font-awesome.css in node_modules. Example:

Before: src: url('../fonts/fontawesome-webfont.eot?v=4.7.0');

After: src: url('../fonts/fontawesome-webfont.eot');

Up to v1.6 of the angular-cli it removed this during compilation. From v1.7 keeps what is in css.

I compared the styles.css of a dist v1.6 and another v6 and that was the difference I found.

I'm using angular v6.0.6 and angular-cli v6.0.8 and it works.

dsalla avatar Jun 26 '18 12:06 dsalla

I'm also having this issue.

@dsalla, this doesn't work for me since I'm not using fontawesome and the fonts I'm using have no version info in the url.

adripanico avatar Jul 17 '18 08:07 adripanico

Well, I finally solve it. In our case, there was a custom font with a space in its name. As soon as I removed the damn space, the warning and the problems were gone.

adripanico avatar Aug 07 '18 06:08 adripanico

Thanks @adripanico ! That definitely helped me out! My font name has a space that has to be there (font awesome) but it did make me think to look to see if I'm manually adding the font anywhere which I was.

I had manually duplicated the font awesome styling to create a sass mixin and in there I had the following line:

font: normal normal 900 14px/1 'Font Awesome 5 Free';

I changed it to not use shorthand like this:

  font-style: normal;
  font-variant: normal;
  font-weight: 900;
  font-size: 14px;
  line-height: 1;
  font-family: 'Font Awesome 5 Free';

And now it works!!

bluecaret avatar Aug 07 '18 15:08 bluecaret

Removing the spaces from the font names fixed it for me too. However I then saw this:

WARNING in Invalid background value

I removed all the background css attributes from my project but still saw the error. I suspect it might be from a package that its pulling from node_modules.

Latest fix following resolving font issue.

Switch optimization back to true in angular.json and switch extractCss to false. This gets me past my background issue.

ImranAhmed avatar Aug 08 '18 07:08 ImranAhmed

Had this issue with angular material mixin @include angular-material-typography. @Ant59 solution did not fix my problem, setting optimization false did the trick.

AntonisFK avatar Aug 24 '18 21:08 AntonisFK

We just ran into this issue. Updating to the latest build does not fix the issue. Turning off the build optimizer did not fix the issue. We had to change to the non-shorthand version.

The warning is very unfriendly as it has no reference to the file the issue came from.

This should be an error not a warning in a production build. It should fail a build not just ignore it.

ccadieux avatar Oct 04 '18 23:10 ccadieux

I have the same issues after renaming my font from "MyFont" to "My Font" I am pretty sure it has something to do with the space in between!

After using the seperate styles "font-family", "font-size"... it works again. With the "font" shortcut property it fails.

zartinn avatar Jan 08 '19 10:01 zartinn

I have the same issues after renaming my font from "MyFont" to "My Font" I am pretty sure it has something to do with the space in between!

After using the seperate styles "font-family", "font-size"... it works again. With the "font" shortcut property it fails.

Of course it has something to do with the space. Have you read anything in this thread?

adripanico avatar Jan 08 '19 10:01 adripanico

Why so rude? Here are several ideas and comments to this problem. I have not seen/read your comment on that.

zartinn avatar Jan 08 '19 10:01 zartinn

Why so rude? Here are several ideas and comments to this problem. I have not seen/read your comment on that.

https://github.com/angular/angular-cli/issues/9648#issuecomment-410951334

https://github.com/angular/angular-cli/issues/9648#issuecomment-411308175

adripanico avatar Jan 16 '19 11:01 adripanico

I have same warning.

I add my fonts in main styles.scss

and use this fonts in scss files

All work fine, but this warning infuriates me.

` Angular CLI: 7.3.5 Node: 10.13.0 OS: win32 x64 Angular: 7.2.8 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.13.5 @angular-devkit/build-angular 0.13.5 @angular-devkit/build-optimizer 0.13.5 @angular-devkit/build-webpack 0.13.5 @angular-devkit/core 7.3.5 @angular-devkit/schematics 7.3.5 @angular/cdk 7.3.4 @angular/cli 7.3.5 @angular/material 7.3.4 @ngtools/webpack 7.3.5 @schematics/angular 7.3.5 @schematics/update 0.13.5 rxjs 6.4.0 typescript 3.2.4 webpack 4.29.0 `

CRACKISH avatar Mar 12 '19 05:03 CRACKISH

Just remove the spaces from the font's filename.

adripanico avatar Mar 13 '19 14:03 adripanico

Hi all,

There seems to be several issues being mentioned in the report, I will go though them a bit in detail here.

Filenames with spaces A the moment there is a bug, which causes a build failure when a font filename has a space.

Font names with spaces Some of the comments above report seeing this warning WARNING in Invalid font values at 3:4. Ignoring This is a bug in clean-css. (I’ll be opening an issue with them tomorrow and add a link below)

Both issues will be addressed in this PR https://github.com/angular/angular-cli/pull/13903

If you are experiencing any other issues, kindly file a new issue with a minimal reproduction.

alan-agius4 avatar Mar 13 '19 17:03 alan-agius4