Expo fontFamily 错误“material-community”不是系统字体,尚未通过 Font.loadAsync 加载

rnk*_*rnk 4 react-native expo

我升级到 expo 34.0.3 和相关的依赖项如下

"dependencies": {
    "@expo/samples": "3.0.3",
    "@expo/vector-icons": "^10.0.3",
    "add": "^2.0.6",
    "expo": "^34.0.3",
    "expo-asset": "^5.0.1",
    "expo-font": "~6.0.1",
    "moment": "^2.24.0",
    "react": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-modal": "^11.3.1",
    "react-native-modal-datetime-picker": "^7.5.0",
    "react-native-snackbar-component": "^1.1.0",
    "react-navigation": "^3.11.1",
    "react-redux": "^7.1.0",
    "redux": "^4.0.4",
    "redux-persist": "^5.10.0"
  },
Run Code Online (Sandbox Code Playgroud)

我的 App.js 大概像这样正确地预加载了字体

  import * as Font from 'expo-font';
  import * as Icon from '@expo/vector-icons';

   .........


  _loadResourcesAsync = async () => {
    return Promise.all([
      Font.loadAsync({
        ...Icon.Ionicons.font,
        ...Icon.MaterialCommunityIcons.font,
      }),
    ]);
  };
Run Code Online (Sandbox Code Playgroud)

现在要明确一点,这段代码在世博升级之前工作得很好。此问题在 Android 和 iOS 设备上都存在。

控制台错误

IKK*_*KKA 17

我已通过在终端中使用以下命令解决了该问题

rm -rf ./node_modules/expo/node_modules/expo-font/


san*_*ula 6

首先确保使用正确的路径加载脚本,如下所示:

 // Load fonts
        await Font.loadAsync({
          ...Ionicons.font,
          "space-mono": require("../assets/fonts/SpaceMono-Regular.ttf"),
          ionicons: require("@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts/Ionicons.ttf"),
          anticon: require("@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts/AntDesign.ttf"),
          "material-community": require("@expo/vector-icons/build/vendor/react-native-vector-icons/Fonts/MaterialCommunityIcons.ttf"),
        });
Run Code Online (Sandbox Code Playgroud)

以下步骤修复了此问题(lang:typescript):

  1. 从根目录删除以下锁定文件
    • 纱线锁
    • 包锁.json
  2. 删除node_modules文件夹
  3. 跑步npm install
  4. 如果您正在使用世博会:
    • 跑步expo install
    • 运行expo start -c以清除缓存并启动应用程序


rnk*_*rnk 5

我能够通过删除yarn.lock(我正在使用yarn)并在升级后删除node_modules来解决这个问题。然后再次运行yarn install。

在此过程中,我还升级了 expo cli、node 并使用了 expo_codemod 来处理对我的代码的任何与升级相关的更改。我还必须“展示安装”像 react-native-gesture-handler 一样移出的软件包

我认为对我来说关键是删除锁定文件并通过 expo start -c 清除缓存