我无法使用 react-native-vector-icons 中的 Icon 组件。我之前可以毫无问题地使用它,但是现在当我将 Icon 组件导入到我使用 Expo 创建的 App.js 文件中时,出现错误。
我已经卸载并重新安装了 Expo,卸载并重新安装了 react-native-elements,并创建了一个新的 Expo 项目。
这是我来自 Expo 的 App.js 文件。唯一与默认 App.js 文件不同的是 Icon 和 Button 组件的导入。Button 组件正确呈现。
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Icon, Button } from 'react-native-elements';
export default function App() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Button title='hello' />
<Icon
name='g-translate'
color='#00aced'
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
这是我的 package.json:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "^33.0.0",
"react": "16.8.3",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
"react-native-elements": "^1.1.0",
"react-native-vector-icons": "^6.6.0",
"react-native-web": "^0.11.4"
},
"devDependencies": {
"babel-preset-expo": "^5.1.1"
},
"private": true
}
我收到错误 [未处理的承诺拒绝:错误:文件目录:///Users/{myusername}/Library/Developer/CoreSimulator/Devices/CE65DD4F-AFFE-46F7-A173-6B25AF30CBCE/data/Containers/Data/Application/ DB21F77C-3BE4-470E-AA62-52E6C8376F0C/Library/Caches/ExponentExperienceData/%2540psoren%252FOctave/ExponentAsset-b06871f281fee6b241d60582ae9369b9.ttf 不存在。] - node_modules/react-native/Modules.js/BatchedBact-native/Modules.js/Batch在 createErrorFromErrorData - node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:104:55 中