Hello everyone I am following an online tutorial about react native but I ran into a problem:
\DUH\src\navigation\Navigator.tsx: @react-navigation/stack could not be found within the project or in these dire
ctories:
node_modules
..\..\..\..\node_modules
6 | createStackNavigator,
7 | StackNavigationProp,
> 8 | } from '@react-navigation/stack';
| ^
9 |
10 | import * as routes from './routes';
11 | import {SelectImageScreen} from '../screens/SelectImageScreen';
This is what my package.json looks like:
{
"name": "DUH",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@react-navigation/native": "^6.1.8",
"react": "18.2.0",
"react-native": "0.72.6",
"react-native-gesture-handler": "^2.13.2",
"react-navigation-stack": "^2.10.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/eslint-config": "^0.72.2",
"@react-native/metro-config": "^0.72.11",
"@tsconfig/react-native": "^3.0.0",
"@types/react": "^18.0.24",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.2.1",
"eslint": "^8.19.0",
"jest": "^29.2.1",
"metro-react-native-babel-preset": "0.76.8",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
},
"engines": {
"node": ">=16"
}
}
As you can see under dependencies I do in fact have react-navigation-stack installed:
"react-navigation-stack": "^2.10.4"
My question is: How can I fix this error??
I did install react-navigation-stack using this command:
npm install react-navigation-stack
, which I found on this post: i could not resolve this bundling error with react navigation v4
You have installed wrong package: You need to install @react-navigation/stack
, not react-navigation-stack
. These two packages are not the same.
npm install @react-navigation/stack
or
yarn add @react-navigation/stack