withDevTools中的Expo错误:React.createElement:类型无效

s5a0g9ez  于 2023-04-12  发布在  React
关注(0)|答案(1)|浏览(116)

当我尝试在Expo中启动我的应用程序时,我得到了这个错误。我的代码似乎根本没有被命中。

ERROR  Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `withDevTools(Anonymous)`.
    in withDevTools(Anonymous)
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent)

下面是我的App.tsx文件,它是最小的:

import { registerRootComponent } from "expo";
import React from "react";
import { Text, View } from "react-native";

function App() {
  return (
    <View>
      <Text>Hello world</Text>
    </View>
  );
}

registerRootComponent(App);
lrl1mhuk

lrl1mhuk1#

在Expo中创建根组件的默认方法是通过App.tsx/App.js中的default export-而不是使用注册函数。当App. tsx中没有默认导出时会导致此错误。
正确的最小实现应该是:

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

export default function App() {
  return (
    <View>
      <Text>Hello world</Text>
    </View>
  );
}

相关问题