简体   繁体   English

无法安装react native和react native元素

[英]Unable to install react native with react native elements

React native cli globally installed version : 2.0.1 React Native CLI全局安装版本:2.0.1

I then used react-native init project_name to set up a project with the native modules. 然后,我使用react-native init project_name设置带有本机模块的项目。

I then tried installing React Native Elements UI Toolkit using yarn add react-native-elements@beta followed by yarn add react-native-vector-icons and then react-native link react-native-vector-icons as per the docs here React Native Elements Docs 然后我尝试使用yarn add react-native-elements@beta然后由yarn add react-native-vector-icons然后使用react-native link react-native-vector-icons安装React Native Elements UI Toolkit ,按照此处的文档React Native元素文档

The install completed successfully with a package.json that looks like this 使用如下所示的package.json成功完成安装

{
"name": "project_react_native",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
  "test": "jest"
},
"dependencies": {
  "react": "16.2.0",
  "react-native": "0.53.3",
  "react-native-elements": "^1.0.0-beta2"
  "react-native-vector-icons": "^4.5.0"
},
"devDependencies": {
 "babel-jest": "22.4.0",
 "babel-preset-react-native": "4.0.0",
 "jest": "22.4.0",
 "react-test-renderer": "16.2.0"
},
"jest": {
 "preset": "react-native"
}
}

I have used the following as my default component 我将以下内容用作默认组件

import React, {Component} from 'react';
import {View} from 'react-native';
import {Button} from 'react-native-elements';
import Icon from 'react-native-vector-icons/FontAwesome';

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={
                    <Icon
                        name='arrow-right'
                        size={15}
                        color='white'
                    />
                }
                text='BUTTON WITH ICON'
            />
        </View>
    );
  }
};

This throws the following error 这将引发以下错误

错误图片

Doesn't look like you can pass a component to the icon prop . 看起来您无法将组件传递给图标prop Change your Button to something along these lines: 将您的Button更改为以下几行:

<Button
  icon={{
      name: 'arrow-right', 
      type: 'font-awesome', 
      buttonStyle: styles.someButtonStyle 
  }}
  text='BUTTON WITH ICON'
/>

See how it goes from there. 看看它从那里如何。

This is an error in metro bundler around handling paths to direct files. 在Metro Bundle中,这是围绕处理直接文件路径的错误。 The issue and workarounds have been logged over at the react-native repo. 问题和解决方法已在本地响应存储库中记录。

You can follow this and this github issue for further references. 您可以关注问题和 github问题,以获取更多参考。

The work around for solving it is 解决它的方法是

Create a rn-cli.config.js file in your root directory and paste in the following code. 在根目录中创建rn-cli.config.js文件,然后粘贴以下代码。

const blacklist = require('metro/src/blacklist')

module.exports = {
  getBlacklistRE() {
   return blacklist([/react-native\/local-cli\/core\/__fixtures__.*/])
 },
}

Be sure to restart the packager. 确保重新启动打包程序。

There are lots of problem in the code just replace your code with this: 在代码中存在很多问题,只需用以下代码替换您的代码:

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>
    );
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM