【问题标题】:Error with Expo fontFamily "material-community" is not a system font and has not been loaded through Font.loadAsyncExpo fontFamily“material-community”错误不是系统字体,尚未通过 Font.loadAsync 加载
【发布时间】:2019-08-04 19:01:54
【问题描述】:

我升级到 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"
  },

我的 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,
      }),
    ]);
  };

现在要明确一点,此代码在 expo 升级之前运行良好。 在 Android 和 iOS 设备上都会出现此问题。

【问题讨论】:

标签: react-native expo


【解决方案1】:

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

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

【讨论】:

  • 这应该是解决方案!完美运行
【解决方案2】:

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

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

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

【讨论】:

  • 非常感谢你!我做了: ncu -u & npm install 显然版本中有一个错误:(新版本工作正常)@use-expo/font ^1.0.1 → ^2.0.0 expo ~36.0.0 → ~37.0.6 expo-font ~8.0.0 → ~8.1.1 react-navigation ^4.3.6 → ^4.3.7 react-navigation-stack ^2.3.10 → ^2.3.11
  • 但在 react-navigation v4.x 中也有一个 bug,其中带有 font-family 和 expo-font 修复了我的 Ionicicons 字体错误
【解决方案3】:

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

 // 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"),
        });

按照以下步骤解决了这个问题(语言:打字稿):

  1. 从根目录中删除以下锁定文件
    • yarn.lock
    • package-lock.json
  2. 删除 node_modules 文件夹
  3. 运行npm install
  4. 如果您使用的是展会:
    • 运行expo install
    • 运行expo start -c清除缓存并启动应用程序

【讨论】:

    【解决方案4】:

    我解决了这个字体问题

    # Like previous posts
    rm -rf node_modules
    rm yarn.lock
    yarn install
    
    # This command as well resolved the material-community issue for me.
    expo install expo-font
    

    【讨论】:

      猜你喜欢
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2019-04-19
      • 1970-01-01
      相关资源
      最近更新 更多