1

I am using react-native and I am trying to add navigation to my project. When I add this line of code:

import { createStackNavigator } from "@react-navigation/stack";, I get this error:

Failed building JavaScript bundle.
Unable to resolve "@react-navigation/stack" from "App.js"

I tried all the solutions suggested in this stackoverflow link but, none worked for me! I reinstalled everything using these commands more than once.

I am using expo.

Omar Diaa
  • 258
  • 4
  • 19

2 Answers2

2

To use stackNavigator, you should install dependencies separately.

After install @react-navigation/native, install @react-navigation/stack:

npm install @react-navigation/stack

Tutorial says that:

To use this navigator, ensure that you have @react-navigation/native and its dependencies (follow this guide), then install @react-navigation/stack:

npm install @react-navigation/stack

glinda93
  • 7,659
  • 5
  • 40
  • 78
2

I had the same issue while using expo.

My solution was just to start expo with the flag to clear the Metro bundler cache

expo start -c
kenan
  • 97
  • 6