I am pretty new to React Native. When I load the simulator in iOS or in Android, I get the following error:
undefined is not a function (near '...(0, _reactNavigation.StackNavigator)...')
<unknown>
home-stack-navigator.js:7:2
loadModuleImplementation
require.js:292:12
<unknown>
App.js:4
loadModuleImplementation
require.js:292:12
<unknown>
AppEntry.js:2
loadModuleImplementation
require.js:292:12
guardedLoadModule
require.js:179:45
global code
I know that this error has been answered and tried following the solutions here, here and here but no success so far.
Here is home-stack-navigator.js
:
import React from 'react';
import { StackNavigator } from 'react-navigation';
import HomeScreen from '../../components/screens/home-screen';
import ShowDetailsScreen from '../../components/screens/show-details-screen';
const HomeStackNavigator = StackNavigator(
{
Main: { screen: HomeScreen },
ShowDetails: { screen: ShowDetailsScreen },
},
{
initialRouteName: 'Main',
headerMode: 'none',
},
);
export default HomeStackNavigator;
And App.js
:
import React from 'react';
import { StatusBar } from 'react-native';
import { DrawerNavigator, DrawerItems } from 'react-navigation';
import HomeStackNavigator from './src/components/navigation/home-stack-navigator';
import { COLORS } from './src/constants/styles';
import styled from 'styled-components/native';
const DrawerContainer = styled.View`
flex: 1;
background-color: ${COLORS.GREY.BRIGHT_GREY};
`;
const AppContainer = styled.View`
flex: 1;
background-color: ${COLORS.GREY.BLACK_RUSSIAN};
`;
const drawerRouteConfig = {
Home: {
screen: HomeStackNavigator,
},
};
const CustomDrawerContentComponent = props => (
<DrawerContainer>
<DrawerItems {...props} />
</DrawerContainer>
);
const drawerNavigatorConfig = {
contentComponent: props => <CustomDrawerContentComponent {...props} />,
};
const AppDrawer = DrawerNavigator(drawerRouteConfig, drawerNavigatorConfig);
export default class App extends React.Component {
render() {
return (
<AppContainer>
<StatusBar hidden={true} />
<AppDrawer />
</AppContainer>
);
}
}
I am also using expo as my builder. Any suggestion would be greatly appreciated.
New Error Log:
Invariant Violation: The navigation prop is missing for this navigator. In react-navigation 3 you must set up your app container directly. More info: https://reactnavigation.org/docs/en/app-containers.html
This error is located at:
in Navigator (at App.js:41)
in RCTView (at View.js:44)
in StyledNativeComponent (created by ForwardRef)
in App (at registerRootComponent.js:17)
in RootErrorBoundary (at registerRootComponent.js:16)
in ExpoRootComponent (at renderApplication.js:34)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AppContainer (at renderApplication.js:33)
Stack trace:
node_modules/@react-navigation/core/dist/navigators/createNavigator.js:35:31 in getDerivedStateFromProps
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:7663:46 in applyDerivedStateFromProps
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:8270:6 in mountClassInstance
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:10480:8 in updateClassComponent
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:14091:21 in performUnitOfWork
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:14129:41 in workLoop
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:14226:15 in renderRoot
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:15193:17 in performWorkOnRoot
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:15090:24 in performWork
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:15047:14 in performSyncWork
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:14925:19 in requestWork
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:14711:16 in scheduleWork
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:15429:15 in scheduleRootUpdate
node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:16142:20 in render
node_modules/react-native/Libraries/ReactNative/renderApplication.js:59:52 in renderApplication
node_modules/react-native/Libraries/ReactNative/AppRegistry.js:101:10 in run
node_modules/react-native/Libraries/ReactNative/AppRegistry.js:195:26 in runApplication
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:349:47 in __callFunction
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:106:26 in <unknown>
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:297:10 in __guard
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:105:17 in callFunctionReturnFlushedQueue
UPDATE:
Error Log:
The component for route 'Home' must be a React component. For example:
import MyScreen from './MyScreen';
Home: MyScreen,
}
You can also use a navigator:
import MyNavigator from './MyNavigator';
Home: MyNavigator,
}