Home > Mobile >  Why do I keep getting the following error : "Unable to resolve module @react-navigation-stack&q
Why do I keep getting the following error : "Unable to resolve module @react-navigation-stack&q

Time:10-15

I am building a project in React Native with expo. I keep getting the same error: enter image description here

Here's my App.js:

import 'react-native-gesture-handler';    
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createStackNavigator } from '@react-navigation-stack';
import Home from './src/components/Home.js';

const Stack = createStackNavigator();

function myStack() {
  return (
    <Stack.Navigator>
      <Stack.Sreen 
      name="Home" 
      component={Home}
      />
    </Stack.Navigator>
  );
}

export default function App() {
  return (
    <NavigationContainer>
      <myStack/>
    </NavigationContainer>
  );
}

And here's a little part of my package.json:

"dependencies": {
    "@react-navigation/core": "react-navigation/core",
    "@react-navigation/native": "react-navigation/native",
    "expo": "~42.0.1",
    "expo-status-bar": "~1.0.4",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-web": "~0.13.12",
    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4"
},

Could you please help me understand why I keep getting this error even though I installed react-navigation-stack?

CodePudding user response:

Please read the instructions for react-navigation v4.x, react-navigation-stack.

Remove the @ sign and you need to use it like this:

import { createStackNavigator } from 'react-navigation-stack';

And to Install please run the below cmd for expo:

expo install react-navigation-stack

Hope this works for you.

  • Related