Avoid Webpack fonts build console errors
Hello,
When dealing with fonts during the application build you can encounter many issues. In particular if you encountered this kind of errors:
Failed to decode downloaded font: ***.woff2
OTS parsing error: Failed to convert WOFF 2.0 font to SFNT
Failed to decode downloaded font: ***.woff
OTS parsing error: incorrect file size in WOFF header
Failed to decode downloaded font: ***.ttf
OTS parsing error: GSUB: table overruns end of file
That means you are having an hard time with your fonts.
First let’s try to identify the source of the problem.
- Even if you are not using Webpack you can encounter this issue because of Git converting your font into text files. Ensure your
.gitattributes
files contains these binary declarations:*.ttf binary *.eot binary *.woff binary *.woff2 binary
- If you are using Webpack then try to switch from
url-loader
tofile-loader
as explained in this article. - If nothing works and you are using Webpack, check-out how you are importing the fonts. In my case I have downloaded “Material Design icons” myself and imported them using:
import '../resources/iconfont/MaterialIcons-Regular.eot'; import '../resources/iconfont/MaterialIcons-Regular.svg'; import '../resources/iconfont/MaterialIcons-Regular.ttf'; import '../resources/iconfont/MaterialIcons-Regular.woff'; import '../resources/iconfont/material-icons.css';
However it was necessary to install the as an npm package
npm install material-design-icons --save
and then import them into my
style.scss
file using:@import "~material-design-icons/iconfont/material-icons.css";
Webpack was now able to process the fonts properly.
Hope these suggestions helped since this issue can be a real pain.
Have a good day!