我只是在使用命令npm start
或expo start
启动时使用a boilerplate code that attempts to load a font在React Native 0.57.1和expo 2.21.2上开始:
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
项目中未出现此类错误 最佳答案
不必像这样加载Icon库就可以在expo中使用Ionicons,只需安装软件包并按如下方式使用它:
import React, { Component } from 'react';
import { Ionicons } from '@expo/vector-icons';
export default class IconExample extends Component {
render() {
return <Ionicons name="md-checkmark-circle" size={32} color="green" />;
}
}