React-native (expo) - 无效类型

Posted

技术标签:

【中文标题】React-native (expo) - 无效类型【英文标题】:React-native (expo) - invalid type 【发布时间】:2017-10-16 04:26:50 【问题描述】:

在使用 Expo 成功初始化 React-native 应用程序的模板构建后,我开始更改以添加我自己的模板,包括 redux。它返回以下错误(在远程调试窗口中):

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

Check your code at App.js:10.
    in Unknown (created by AwakeInDevApp)
    in RCTView (at View.js:514)
    in View (created by AwakeInDevApp)
    in AwakeInDevApp (at registerRootComponent.js:21)
    in ExponentRootComponent (at renderApplication.js:35)
    in RCTView (at View.js:514)
    in View (at AppContainer.js:93)
    in RCTView (at View.js:514)
    in View (at AppContainer.js:92)
    in AppContainer (at renderApplication.js:34)
reactConsoleErrorHandler @ crna-entry.bundle:6725
newConsoleFunc @ crna-entry.bundle:52943
console.error @ crna-entry.bundle:36227
printWarning @ crna-entry.bundle:3015
warning @ crna-entry.bundle:3036
createElement @ crna-entry.bundle:17021
exports.default @ crna-entry.bundle:81790
(anonymous) @ crna-entry.bundle:21644
measureLifeCyclePerf @ crna-entry.bundle:21459
_constructComponentWithoutOwner @ crna-entry.bundle:21643
_constructComponent @ crna-entry.bundle:21620
mountComponent @ crna-entry.bundle:21513
mountComponent @ crna-entry.bundle:17847
mountChildren @ crna-entry.bundle:21043
initializeChildren @ crna-entry.bundle:20502
mountComponent @ crna-entry.bundle:20562
mountComponent @ crna-entry.bundle:17847
performInitialMount @ crna-entry.bundle:21686
mountComponent @ crna-entry.bundle:21590
mountComponent @ crna-entry.bundle:17847
performInitialMount @ crna-entry.bundle:21686
mountComponent @ crna-entry.bundle:21590
mountComponent @ crna-entry.bundle:17847
performInitialMount @ crna-entry.bundle:21686
mountComponent @ crna-entry.bundle:21590
mountComponent @ crna-entry.bundle:17847
mountChildren @ crna-entry.bundle:21043
initializeChildren @ crna-entry.bundle:20502
mountComponent @ crna-entry.bundle:20562
mountComponent @ crna-entry.bundle:17847
performInitialMount @ crna-entry.bundle:21686
mountComponent @ crna-entry.bundle:21590
mountComponent @ crna-entry.bundle:17847
mountChildren @ crna-entry.bundle:21043
initializeChildren @ crna-entry.bundle:20502
mountComponent @ crna-entry.bundle:20562
mountComponent @ crna-entry.bundle:17847
performInitialMount @ crna-entry.bundle:21686
mountComponent @ crna-entry.bundle:21590
mountComponent @ crna-entry.bundle:17847
performInitialMount @ crna-entry.bundle:21686
mountComponent @ crna-entry.bundle:21590
mountComponent @ crna-entry.bundle:17847
performInitialMount @ crna-entry.bundle:21686
mountComponent @ crna-entry.bundle:21590
mountComponent @ crna-entry.bundle:17847
mountComponentIntoNode @ crna-entry.bundle:22829
perform @ crna-entry.bundle:18133
batchedMountComponentIntoNode @ crna-entry.bundle:22836
perform @ crna-entry.bundle:18133
batchedUpdates @ crna-entry.bundle:17658
batchedUpdates @ crna-entry.bundle:17727
renderComponent @ crna-entry.bundle:22881
render @ crna-entry.bundle:6353
renderApplication @ crna-entry.bundle:49001
run @ crna-entry.bundle:48790
runApplication @ crna-entry.bundle:48830
__callFunction @ crna-entry.bundle:3451
(anonymous) @ crna-entry.bundle:3322
guard @ crna-entry.bundle:3286
callFunctionReturnFlushedQueue @ crna-entry.bundle:3321
(anonymous) @ debuggerWorker.js:71
crna-entry.bundle:6717 Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

Check the render method of `StatelessComponent`.
handleException @ crna-entry.bundle:6717
handleError @ crna-entry.bundle:6577
reportFatalError @ crna-entry.bundle:683
guard @ crna-entry.bundle:3288
callFunctionReturnFlushedQueue @ crna-entry.bundle:3321
(anonymous) @ debuggerWorker.js:71
crna-entry.bundle:52943 Remote debugger is in a background tab which may cause apps to perform slowly. Fix this by foregrounding the tab (or opening it in a separate window).
newConsoleFunc @ crna-entry.bundle:52943
console.warn @ crna-entry.bundle:36235
(anonymous) @ debuggerWorker.js:25
(anonymous) @ debuggerWorker.js:53

App.js 是:

import React from 'react';
import Provider from 'react-redux';
import HomeScreen from './components/HomeScreen';
import createStore from './createStore';

const store = createStore();

export default () => (
  <Provider store=store>
    <HomeScreen />
  </Provider>
);

以及完整的代码: https://github.com/wastelandtime/rpgame

请指教。

【问题讨论】:

【参考方案1】:

在您的 App.js 中,您将 Provider 作为默认模块导入,但它实际上被命名为 export。

所以,换成

import Provider from 'react-redux';

【讨论】:

就是这样。谢谢你。我不知道我是怎么错过的。

以上是关于React-native (expo) - 无效类型的主要内容,如果未能解决你的问题,请参考以下文章

使用 react-native (expo) 切换手电筒

React-native refs 和 Expo Camera

React-Native (expo) 检索初始主题(或任何初始化值)

不使用 react-native 的 Expo 分支

expo 应用程序中的 React-native 安装问题

react-native / expo / expo-google-app-auth vs expo-google-sign-in