React-Native Invariant Violation:元素类型无效

时间:2017-12-15 03:48:40

标签: javascript android ios reactjs react-native

当我要在我的iPhone Expo上运行我的本机应用程序时,此错误显示在红色背景区域。

  

不变违规:元素类型无效:预期字符串(对于内置组件)   或类/函数(对于复合组件)但得到:对象。您   可能忘记从您定义的文件中导出组件。

这是'src / components /'文件夹中的App.js

import React, { Component } from 'react';
import { View, Text } from 'react-native';


export default class App extends Component {
  render() {
    return (
    	<View>
      		<Text>Hello</Text>
      	</View>
    );
  }
}

这是react-native app文件夹中的主要App.js.

import App from './src/components/App';

我使用expo app运行此代码。我该如何解决这个错误?

4 个答案:

答案 0 :(得分:5)

Expo希望您从/App.js导出组件。但是现在你只导入/App.js。世博会没有收到任何组成部分。您需要导出导入的组件,如下所示:

export default App;

旁注:仅在必要时才使用类组件。

答案 1 :(得分:4)

在我的情况下,而不是像这样导出:

export default App;

...我出口如下:

export {LoginForm};

完全正常。

答案 2 :(得分:1)

我有同样的问题,我把 class yourclassname extends Component 之前 2018-08-25 09:59:04.733 [destination = platform_data , address = ip:3306 , EventParser] ERROR com.alibaba.otter.canal.common.alarm.LogAlarmHand ler - destination:platform_data[com.alibaba.otter.canal.parse.exception.CanalParseException: com.alibaba.otter.canal.parse.exception.CanalParseException: parse row data failed. Caused by: com.alibaba.otter.canal.parse.exception.CanalParseException: parse row data failed. Caused by: com.alibaba.otter.canal.parse.exception.CanalParseException: com.google.common.util.concurrent.UncheckedExecutionException: com.alibaba.otter.canal.parse.exception.CanalParseException: fetch failed by table meta:`platform_data`.`tmp_presto_0e13f1bc14574ec4ae4950cade1bc360` Caused by: com.google.common.util.concurrent.UncheckedExecutionException: com.alibaba.otter.canal.parse.exception.CanalParseException: fetch failed by table meta:`platform_data`.`tmp_presto_0e13f1bc145 74ec4ae4950cade1bc360` at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2203) at com.google.common.cache.LocalCache.get(LocalCache.java:3937) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824) at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4830) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.TableMetaCache.getTableMeta(TableMetaCache.java:185) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.getTableMeta(LogEventConvert.java:793) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.parseRowsEvent(LogEventConvert.java:457) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.parse(LogEventConvert.java:127) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.parse(LogEventConvert.java:68) at com.alibaba.otter.canal.parse.inbound.AbstractEventParser.parseAndProfilingIfNecessary(AbstractEventParser.java:345) at com.alibaba.otter.canal.parse.inbound.AbstractEventParser$3$1.sink(AbstractEventParser.java:187) at com.alibaba.otter.canal.parse.inbound.mysql.MysqlConnection.dump(MysqlConnection.java:154) at com.alibaba.otter.canal.parse.inbound.AbstractEventParser$3.run(AbstractEventParser.java:227) at java.lang.Thread.run(Thread.java:745) Caused by: com.alibaba.otter.canal.parse.exception.CanalParseException: fetch failed by table meta:`platform_data`.`tmp_presto_0e13f1bc14574ec4ae4950cade1bc360` Caused by: java.io.IOException: ErrorPacket [errorNumber=1146, fieldCount=-1, message=Table 'platform_data.tmp_presto_0e13f1bc14574ec4ae4950cade1bc360' doesn't exist, sqlState=42S02, sqlStateMarker=#] with command: desc `platform_data`.`tmp_presto_0e13f1bc14574ec4ae4950cade1bc360` at com.alibaba.otter.canal.parse.driver.mysql.MysqlQueryExecutor.query(MysqlQueryExecutor.java:61) at com.alibaba.otter.canal.parse.inbound.mysql.MysqlConnection.query(MysqlConnection.java:96) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.TableMetaCache.getTableMetaByDB(TableMetaCache.java:89) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.TableMetaCache.access$000(TableMetaCache.java:32) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.TableMetaCache$1.load(TableMetaCache.java:62) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.TableMetaCache$1.load(TableMetaCache.java:52) at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527) at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319) at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282) at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197) at com.google.common.cache.LocalCache.get(LocalCache.java:3937) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824) at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4830) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.TableMetaCache.getTableMeta(TableMetaCache.java:185) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.getTableMeta(LogEventConvert.java:793) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.parseRowsEvent(LogEventConvert.java:457) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.parse(LogEventConvert.java:127) at com.alibaba.otter.canal.parse.inbound.mysql.dbsync.LogEventConvert.parse(LogEventConvert.java:68) at com.alibaba.otter.canal.parse.inbound.AbstractEventParser.parseAndProfilingIfNecessary(AbstractEventParser.java:345) at com.alibaba.otter.canal.parse.inbound.AbstractEventParser$3$1.sink(AbstractEventParser.java:187) at com.alibaba.otter.canal.parse.inbound.mysql.MysqlConnection.dump(MysqlConnection.java:154) at com.alibaba.otter.canal.parse.inbound.AbstractEventParser$3.run(AbstractEventParser.java:227) at java.lang.Thread.run(Thread.java:745) 在App.js中

答案 3 :(得分:1)

以以下样式进行导出时出现此错误,但未指定默认导出。我没有指定默认值,因为我正在从一个文件中导出多个小组件。

library(ggplot2)
#container list to hold ggplots
l <- list()

#unique cylinder groups
cyl_groups <- sort(unique(mtcars$cyl))

#iterate through each cylinder group, plotting mpg vs disp
for(j in seq_along(cyl_groups)){
  l[[j]] <- ggplot(mtcars[mtcars$cyl == cyl_groups[[j]], ], aes(mpg, disp)) + geom_point() + ggtitle(paste0("Cylinders = ", cyl_groups[j]))
}

#save into one PDF
pdf("plots.pdf", onefile = TRUE)
for(i in seq_along(l)) {
  print(l[[i]])
}
dev.off()

我可以通过在导入语句中添加方括号来使其工作。

export const  Modal  = (props) => (
    <div className="someClass">
    </div>        
  )