2

I'm using Expo Google Fonts and the useFonts() method to import the fonts for my app. However I get the following error but I thought I didn't need to use Font.loadasync with the Google Fonts (as per docs here). Can you let me know what I'm doing wrong here?

import React, { useState } from "react";
import { View, TouchableOpacity, Text, StyleSheet, Platform } from 'react-native'
import { useFonts, Kanit_400Regular, Kanit_500Medium, Kanit_700Bold } from '@expo-google-fonts/kanit';
import Colors from '../constants/Colors'

const Header = props => {

  useFonts({Kanit_400Regular, Kanit_500Medium, Kanit_700Bold})

  return (
    <View style={styles.headerContainer}>
      <View style={styles.logo}>
        <Text style={styles.headerText}>HEADER</Text>
      </View>
      <View>
        <Text style={{...styles.headerText, fontSize: 14 }}>LOGIN</Text>
      </View>
    </View>
  )
} 

const styles = StyleSheet.create({
  headerContainer: {
    padding: 15,
    paddingTop: Platform.OS === 'android' ? 40 : 15,
    backgroundColor: 'rgba(0,0,0,0.3)',
    justifyContent: 'space-between',
    height: Platform.OS === 'android' ? '12%' : '10%',
    borderBottomColor: Colors.borderGold,
    borderBottomWidth: 1,
    alignItems: 'center',
    flexDirection: 'row',
    fontSize: 16,
  },
  headerText: {
    fontSize: 16,
    color: Colors.primary,
    fontFamily: 'Kanit_500Medium',
  }
})

export default Header

enter image description here

Jat90
  • 493
  • 1
  • 10
  • 22

1 Answers1

4

In my case the problem was an incompatible version of expo-font in the package.json with the version of expo installed.

I downgraded from 10.1.0 to 10.0.4 and the fonts are now loading fine.

Remember to use expo install expo-font

I hope this helps

Marco
  • 41
  • 2
  • Could you please add your package.json so we know which version of Expo you're using? – Madhav Malhotra Aug 21 '22 at 19:46
  • Had similar issue, but downgraded from `10.2.0` to `10.1.0`. – Soullivaneuh Sep 18 '22 at 16:36
  • I cannot believe I wasted several hours on this, and this solved it! I had used npm to install... I guess whatever the latest is, isn't compatible with Expo yet. What a pain! Would be great if they added some error handling!!!!!!!!! – Brian Birtle Nov 11 '22 at 04:53
  • The recommended way to install expo packages is to run `expo install package-name`. You can also fix incompatible package version with `expo doctor --fix-dependencies` – Odunsi Nov 17 '22 at 09:51