2

I am trying to import a web-font in a certain component in my Vue App (created with Vue cli webpack template). Inside the one of my components I try to import the fonts, by referencing a _fonts.scss within the project that has the contents:

@font-face {
  font-family: 'SomeFont';
  src: url('~/assets/fonts/SomeFont-Regular.woff2') format('woff2'),
  url('~/assets/fonts/SomeFont-Regular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
}

Then, when I open the app, I get this error:

Failed to decode downloaded font: http://localhost:8080/assets/fonts/SomeFont-Regular.woff2
Failed to decode downloaded font: http://localhost:8080/assets/fonts/SomeFont-Regular.woff

With this too:

OTS parsing error: invalid version tag
OTS parsing error: invalid version tag

I searched online for this problem and found nothing, or some relatable circumstances

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Roger Federer
  • 329
  • 2
  • 6
  • 12

2 Answers2

8

Try to use relative path when importing fonts in url(). Without '~/fontPath'

Example

@font-face {
  font-family: 'MyFont';
  src: url("../assets/fonts/MyFont.woff2") format('woff2');
  font-weight: normal;
  font-style: normal;
}
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Anton Nikprelaj
  • 166
  • 1
  • 2
  • 3
    But why does this help?! – katerlouis Jun 14 '20 at 13:26
  • 1
    **This is the correct answer** from the hundreds of answers here on SO. Paths are the number one problem when working with fonts. I'm building a VueJS app in VSC and all I did was to change `/src/assets/fonts/icomoon.eot?uoqhn7` to `../src/assets/fonts/icomoon.eot?uoqhn7` and it worked. I have no idea why. **Vue has some 'issues' with relative paths.** For example: in the same file `img src="@/assets/images/image.png"` will work, but `src: url("@/assets/fonts/icomoon.eot?uoqhn7");` will not. – GeorgicaFaraFrica Nov 05 '20 at 18:01
3

I had the same problem and found the answer here Vue Cli 3 Local fonts not loading. In short, you have to replace ../assets with ~@/assets.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Sjoerd Oudman
  • 129
  • 1
  • 5