I’ve started a brand new react native project. When I attempt to install react native, I get dependency resolution errors. Could there be an issue with react 18.2 and react-native 0.70.6?
What is the best versions to use? Should I start with react 17?
npm install react-native
I receive the following output:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"^18.2.0" from the root project
npm ERR! peer react@"*" from @react-navigation/[email protected]
npm ERR! node_modules/@react-navigation/core
npm ERR! @react-navigation/core@"^6.4.5" from @react-navigation/[email protected]
npm ERR! node_modules/@react-navigation/native
npm ERR! @react-navigation/native@"^6.1.1" from the root project
npm ERR! 3 more (@react-navigation/elements, ...)
npm ERR! 12 more (@react-navigation/elements, ...)
From my package.json:
"dependencies": {
"@react-navigation/native": "^6.1.1",
"@react-navigation/native-stack": "^6.9.6",
"@react-navigation/stack": "^6.3.9",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-native": "^0.70.6",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
2
Answers
As of
[email protected]
, you should be using React 18.1.0:if you want to get correct and match version with react, then you have to run
npx react-native init YourProjectName
. Do not install each of them one by one, unless you know the match compatible version from each react native. Please re-read from official RN documentation.The Simplest and easiest way , you just run
npx react-native init YourProjectName
If you want to get simple react native boilerplate, You can install from handidev boilerplate. It is already used latest react native version.
for typescript version:
npx react-native init MyAppName --template @handidev/react-native-typescript-boilerplate
for javascript plain version:
npx react-native init MyApp --template @handidev/react-native-typescript-boilerplate
Reference: