Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting the error in react native - fontFamily "ionicons" is not a system font

I am getting the following error in react native - fontFamily "ionicons" is not a system font and has not been loaded through Font.loadAsync.

  • If you intended to use a system font, make sure you typed the name correctly and that it is supported by your device operating system.

I am trying to import the expo vector icons.

import { Ionicons } from '@expo/vector-icons';

and using the icon

<Button transparent>
            <Ionicons name="md-checkmark-circle" size={32} color="green" />
        </Button>

but getting the above mentioned error.

like image 309
Upasana Chauhan Avatar asked Jul 18 '19 15:07

Upasana Chauhan


4 Answers

Another possible solution I happened upon after of hours of looking at code that should work and which is identical to the sample and the excellent previous answer.

If you have been upgrading Expo this may be your answer.

  1. Delete node_modules
  2. Delete package-lock.json
  3. run expo install
  4. run expo start -c
like image 199
Patrick Avatar answered Oct 19 '22 20:10

Patrick


If nuking node_modules is not working, then make sure you don't have installed multiple versions of expo-font.

  1. Remove expo-font from node_modules/expo/node_modules/expo-font/.
  2. Remove expo-font form list of dependencies from node_modules/expo/package.json.
  3. Run expo r -c

For details Expo cannot load a font due to multiple versions of expo-font installed.

like image 45
skmak Avatar answered Oct 19 '22 20:10

skmak


The library @expo/vector-icons is only installed by default on the template project that get through expo init -- it is part of the expo package .

If you created your project using react-native init use react-native-vector-icons instead

Installation

npm i react-native-vector-icons

react-native link react-native-vector-icons

Usage

import Icon from 'react-native-vector-icons/Ionicons';

<Button transparent>
    <Icon name="md-checkmark-circle" size={32} color="green" />
</Button>

OR

try loading Ionicons using Font.loadAsync in your App.js

async componentDidMount () {
    await Expo.Font.loadAsync({
        Ionicons: require('@expo/vector-icons/fonts/Ionicons.ttf'),
    });
like image 3
sachin mathew Avatar answered Oct 19 '22 21:10

sachin mathew


Adding Iconicons in loadAsync solved this bug for me.

async componentDidMount () {
    await Expo.Font.loadAsync({
        Ionicons: require('@expo/vector-icons/fonts/Ionicons.ttf'),
    });
like image 1
Rukmoni Nagarajan Avatar answered Oct 19 '22 20:10

Rukmoni Nagarajan