Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got undefined

I have just started learning how to create apps using React Native. After learning about the Stack Navigator, I attempted to try it out but I am getting this error. Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s%s, undefined, You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

App.js

import React from 'react';
import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { NavigationNativeContainer } from '@react-navigation/native';
import {createStackNavigator}  from '@react-navigation/stack';


const Stack = createStackNavigator();
export default function App() {
    return( 
    <NavigationNativeContainer>
      <Stack.Navigator>
      <Stack.Screen name="Home" component={HomeScreen}/>
       </Stack.Navigator>
      </NavigationNativeContainer>
    );
}
const HomeScreen=(props)=> {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Home Screen</Text>
    </View>
  );
}

Package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/core": "^5.7.0",
    "@react-navigation/native": "^5.4.0",
    "@react-navigation/stack": "^5.3.7",
    "expo": "~37.0.3",
    "expo-font": "~8.1.0",
    "native-base": "^2.13.12",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-reanimated": "^1.8.0",
    "react-native-safe-area-context": "^1.0.0",
    "react-native-screens": "^2.7.0",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "~8.1.0"
  },
  "private": true
}

like image 358
Michelle Avatar asked Mar 19 '26 10:03

Michelle


1 Answers

change

import { NavigationNativeContainer } from '@react-navigation/native';

to

import { NavigationContainer } from '@react-navigation/native';


  <NavigationContainer>
  <Stack.Navigator>
  <Stack.Screen name="Home" component={HomeScreen}/>
   </Stack.Navigator>
  </NavigationContainer>

When react-navigation was in beta, it was NavigationNativeContainer,now it is NavigationContainer

Hope this helps!

like image 131
Goskula Jayachandra Avatar answered Mar 21 '26 23:03

Goskula Jayachandra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!