question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use custom font with RN >= 0.60 --template typescript. react-native.config.js ignored

See original GitHub issue

I am trying to use a custom font in a freshly new React-native project made with the typescript template and I do not succeed to add a custom font family.

All the doc I found told me to use rnpm which has been now deprecated in favor of a react-native.config.js file in the root folder. I therefore created this file in my project but I did not see anywhere where to tell the react-native builder to read it and therefore I get the error font_name not found

Has anyone any suggestion ?

React Native version:

System:
    OS: macOS 10.14.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
    Memory: 1.71 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.10.0 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
    Android SDK:
      API Levels: 23, 24, 25, 26, 27, 28, 29
      Build Tools: 27.0.3, 28.0.2, 28.0.3, 29.0.0
      System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-Q | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.2 AI-181.5540.7.32.5056338
    Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.0 => 0.60.0 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Steps To Reproduce

  1. react-native init your_project --template typescript
  2. Create a folder assets/fonts and put all your custom fonts : (mine were Lato-(Regular,…).ttf)
  3. Create a react-native.config.js in the root folder of your project as follow
module.exports = {
  project: {
    ios: {},
    android: {}, // grouped into "project"
  },
  assets: ['./assets/fonts'], // stays the same
  // commands: require('./path-to-commands.js'), // formerly "plugin", returns an array of commands
};
  1. Use the font in the app Component as styling of you text
  2. run react-native run-ios
  3. You’ll get an error “font Lato (in my case) not found”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:19

github_iconTop GitHub Comments

10reactions
Ravi448commented, Jul 20, 2019

got the mistake,

Config should look like ::

module.exports = {
      assets: ['./Source/Resources/Fonts/']
  };
Instead of
module.exports = {
    dependency: {
      assets: ['./Source/Resources/Fonts/']
    },
  };

This should be mentioned in the doc. And both react-native link & yarn react-native link work fine

3reactions
alitelecommented, Sep 21, 2019

I got it working for RN v0.60.5 by doing these steps.

1- Created a file in the react-native.config.js in the root of the project. 2- Paste this below code into above created file

module.exports = { project: { ios: {}, android: {}, }, assets: ['./assets/fonts'] }; . // Note assets folder created at root level (assets->fonts->YOUR FONT FILE)

3- Link assets to your project by running react-native link 4- Run project react-native run-ios

hopefully it should work fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't link assets (fonts) in react native >= 0.60 - Stack Overflow
Here is the complete walkthrough for linking custom fonts. ... Using RN 0.60.8 with a react-native-config.js file should allow you to link ...
Read more >
How to add custom fonts in React Native - LogRocket Blog
In this guide we will be exploring ways to add custom fonts in a React Native app. To follow along, you should be...
Read more >
Troubleshooting | React Navigation
Troubleshooting. This section attempts to outline issues that users frequently encounter when first getting accustomed to using React Navigation.
Read more >
Adding Custom Fonts (A Complete Guide) - React Native 0.60+
A complete guide to adding custom fonts on React Native and fixing any lags · Creating a new application · Adding font files...
Read more >
Blog · React Native Archive
A framework for building native apps using React. ... source of the `metro.config.js` file in the 0.59 template,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found