1.7.0 fonts are corrupted after prod build
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
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.
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",
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";
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.
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.
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.
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.
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.
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.
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!!
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.
Had this issue with angular material mixin @include angular-material-typography. @Ant59 solution did not fix my problem, setting optimization false did the trick.
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.
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.
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?
Why so rude? Here are several ideas and comments to this problem. I have not seen/read your comment on that.
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
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 `
Just remove the spaces from the font's filename.
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.