当我尝试在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);
1条答案
按热度按时间lrl1mhuk1#
在Expo中创建根组件的默认方法是通过App.tsx/App.js中的
default export
-而不是使用注册函数。当App. tsx中没有默认导出时会导致此错误。正确的最小实现应该是: