Native-React + Expo:无法从“ src / boot / setup.js”解析“ @ expo / vector-icons / fonts / Ionicons.ttf”

时间:2019-07-15 16:18:58

标签: javascript reactjs react-native expo ionicons

我只是在启动过程中使用npm start使用a boilerplate code that attempts to load a font在React Native 0.57.1​​ 和expo 2.21.2 上开始,或者expo start

import * as Expo from "expo";

....

async componentWillMount() {
    await Expo.Font.loadAsync({
        Ionicons: require("@expo/vector-icons/fonts/Ionicons.ttf"),
    });

    this.setState({ isReady: true });
}

这给出了错误

  

无法从“ src / boot / setup.js”解析“ @ expo / vector-icons / fonts / Ionicons.ttf”

尝试#1: npm install --save @expo/vector-icons。但是,这样做不能解决错误。

为什么会这样,我们如何解决此问题?谢谢!


更新:按照mialnika和Carlos Abraham的建议,该错误已修复,但遇到了一个新错误:

  

Expo SDK需要运行Expo。似乎本机的Expo模块不可用,并且此代码未在Expo上运行。

这是通过在实际iPhone上使用iOS Expo客户端在通过LAN连接的Expo的开发模式下运行RN应用程序完成的。

新的expo init项目中不会出现此类错误

2 个答案:

答案 0 :(得分:1)

我不确定您所使用的矢量图标的版本,但是可以检查此链接是否可用:)? '@ expo / vector-icons / website / src / fonts / Ionicons.ttf';

答案 1 :(得分:1)

为了能够在Expo中使用Ionicons,不必像这样加载Icon库,只需安装软件包并按如下方式使用它即可:


string[] files;
bool error = false;

    try   
    {        
          files = Directory.GetFiles(addDir /* this is the folder path*/, "*.txt", SearchOption.AllDirectories);

    }
    catch(Exception ex)
    {
        // the code will jump here if there any access restrictions
        MessageBox.Show(ex.Message);

        error = true;
    }

    if(!error)
    {
        foreach (string fi in files)
        {
            string fnameonly = System.IO.Path.GetFileNameWithoutExtension(fi);
            _listView1.Items.Add(fnameonly);
        }
    }