这是Metro捆绑器中处理直接文件路径的错误。在react-native repo中记录了问题和变通方法。
你可以关注 这个 和 这个 github问题供进一步参考。
解决它的工作是
创建一个 rn-cli.config.js 将文件放在根目录中并粘贴以下代码。
rn-cli.config.js
const blacklist = require('metro/src/blacklist') module.exports = { getBlacklistRE() { return blacklist([/react-native\/local-cli\/core\/__fixtures__.*/]) }, }
务必重新启动打包器。
看起来你不能将组件传递给图标道具 。 将按钮更改为以下内容:
<Button icon={{ name: 'arrow-right', type: 'font-awesome', buttonStyle: styles.someButtonStyle }} text='BUTTON WITH ICON' />
看看它是如何发生的。
代码中有很多问题,只需用以下代码替换代码:
import React, {Component} from 'react'; import {View} from 'react-native'; import {Button, Icon} from 'react-native-elements'; export default class App extends Component { render() { return ( // Try setting `flexDirection` to `column`. <View style={{flex: 1, flexDirection: 'row'}}> <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}}/> <Button icon={{ name:'arrow-right', size:15, type: 'font-awesome', color:'white', }} title='BUTTON WITH ICON' /> </View> ); } };