274

Getting the following message when I init a new project and then launch the Xcode emulator:

React-Native Version Mismatch

Javascript Version 0.50.1 Native version: 0.50.0

Make sure you have rebuilt the native code. ...

Does anyone know what is going on here and can help me?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Sam Rao
  • 4,361
  • 5
  • 19
  • 21

49 Answers49

459

This is what I've done with it:

Close all terminals and run build again.

You may forget to close nodejs terminal from another project, and they happen to have installed different react version.

So the code fetches from nodejs server conflicts with the native one.

Val
  • 21,938
  • 10
  • 68
  • 86
42

In case you created your react-native app using create-react-native-app. You should have a app.json (expo). and a package.json file, check if the expo versions match and change accordingly. For example in my case the problem was that in the app.json file I had a 25.0.0 version for the expo sdkVersion attribute, I change that to 23.0.0 and everything worked.

package.json:

"dependencies": {
    "expo": "^23.0.4",
    "react": "16.0.0",
    "react-native": "^0.50.4"
  }

app.json:

{
  "expo": {
    "sdkVersion": "23.0.0" // before was 25.0.0
  }
}
victoryoalli
  • 1,897
  • 2
  • 12
  • 11
  • This worked for me! Quick update: you may not use a direct npm module for your react-native package and instead have a tarball. If that's the case, you can use react-native status to verify your version of RN. :) – blakeface Dec 09 '18 at 19:45
15

Just go to your android/app/build.gradle and then add to the dependencies section:

dependencies{
compile ("com.facebook.react:react-native:0.50.3") { force = true } 
}

/// the react native version can be found in package.json

Noitidart
  • 35,443
  • 37
  • 154
  • 323
kunal pal
  • 314
  • 2
  • 9
8

For Android developers who couldn't get it fixed by just closing and rebuilding, Manually uninstall the app on the emulator/device.

Nadun Liyanage
  • 463
  • 3
  • 10
8

just force react native version in your android's app level gradle file, in the dependencies section.

compile ("com.facebook.react:react-native:0.52.0") { force = true }

worked for me

Noitidart
  • 35,443
  • 37
  • 154
  • 323
Shubham Goel
  • 1,962
  • 17
  • 25
  • 3
    This worked for me. I have 0.53.3. I added a force with 0.53.3, restarted terminals, ran `npm start -- --reset-cache` and ran `react-native run-android` – Florin Dobre May 15 '18 at 12:30
7

If you're running your React Native app through Expo, upgrading React Native is liable to cause this error (as noted at https://github.com/expo/expo/issues/923).

If that's your scenario, your options are:

  1. Bump Expo (which is listed in your package.json) to a version that is compatible with your React Native version (if one exists, which may not be the case - judging by the linked issue, I figure that Expo support trails React Native releases).
  2. Discard your changes, delete and reinstall your Node modules, Eject from Expo, and then (after checking that you can still run your app post-ejection) try your upgrade again.
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
  • Expo only supports react-native up to 59.8 at the time of writing. For expo/react-native compatibility, see https://docs.expo.io/versions/latest/sdk/overview/#sdk-version (it's not the exact same cause of error as the OP, but seems relevant to note.) – Tijs Maas Dec 30 '19 at 00:42
6

I've never seen this error before, but whenever I can't get Xcode and React-Native to play well together, I do a couple of things. Check what version of Xcode I'm working with. If it needs to be updated, I update it. Then clearing watchman and the cache are the second place I go. I don't use the reset cache command. It always says that I need to verify the cache, so I skip that (you can do it though, I just get confused). I use rm -rf $TMPDIR/react-* to get rid of any cached builds. If that doesn't work, I try to build the app in Xcode, then work my way from there, to build it with react-native run-ios. With this error message, it seems you might start by trying to build it with Xcode. Hope that helps...let me know your progress with it. Good luck! (Also, you could update to RN 0.51 as another attempt to get your versions synced.)

Jared Nelson
  • 254
  • 4
  • 13
  • The other thing is that I played around with expo. Wonder if that messed things up – Sam Rao Dec 12 '17 at 02:01
  • You could just do npm install --save react-native@0.51 But, I'd try building it with Xcode first. Have you done that yet? If you need help, let me know. – Jared Nelson Dec 12 '17 at 02:03
6

I had this problem for the longest time and none of the above solutions helped. I was in the middle of upgrading react native in a create-react-native-app project until I found out that not all versions of Expo support the latest React Native.

Found this page linked in the documentation that shows which version combinations of React Native, React, and Expo are officially supported:

Source: https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md

Editing the app.json and package.json files to match the corresponding versions and running npm install got everything working again.

Yatit Thakker
  • 522
  • 5
  • 4
6

I am using a physical device, in my case this solved the problem:

  1. Uninstall the app
  2. lsof -i :8081
  3. kill -9 PID
  4. Rebuild the app (react-native run-android or react-native run-ios)
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
ade_anugerah
  • 61
  • 1
  • 1
  • Simply killing all PIDs from `lsof -i :8081` and rebuilding did it for me on iOS Simulator. – Ronan Boiteau May 18 '19 at 18:57
  • The same here - tried Rimraf node_modules, npm start —reset-cache, etc - nothing worked. Then I did as above - uninstalled app, used taskkill /im node.exe and taskkill /f /PID(number given in last step, of existing PID), then react-native run-android. Worked a treat! – user1641906 Aug 26 '19 at 15:25
5

In your build.gradle file add the following

implementation ("com.facebook.react:react-native:0.51.0") {
    force = true;
}

replace 0.51.0 with the version in your package.json

Nitish Phanse
  • 552
  • 1
  • 9
  • 16
4

Try installing the dependencies again. That worked for me-

1.) yarn/npm install
2.) yarn/npm start --reset-cache

Aditi Gupta
  • 876
  • 7
  • 5
4

I have tried the solutions above but adding this to AndroidManifest.xml seems to fix it.

  android:usesCleartextTraffic="true"
ketimaBU
  • 901
  • 4
  • 15
  • 35
3

For me it was due to react-native version in dependency section of package.json file. It was:

"dependencies": {
"expo": "^27.0.1",
"react": "16.3.1",
"react-native": "~0.55.0"
}

I chaged it to:

"dependencies": {
"expo": "^27.0.1",
"react": "16.3.1",
"react-native": "0.52.0"
}

Now it works fine.

Seyed Morteza Mousavi
  • 6,855
  • 8
  • 43
  • 69
3

In my case installing a new virtual device helped. Now I am using 1 device per app.

Luminita Balas
  • 604
  • 1
  • 5
  • 4
3

It happens sometimes when you try to run without closing the node server, in which the previous app was running, so try restarting React.To do so, just run the following commands:

1. To kill current processes
killall node -9 

2. To Start React  Native
react-native start 

3. Then Run android
react-native run-android
civani mahida
  • 314
  • 3
  • 8
3

For my case I'm facing it on iOS, and I've tried to reset and clear all cache using below command but failed too, despite many comments saying that the root cause is there is react packager running somewhere accidentally, I've restarted my mac and the problem still remained.

watchman watch-del-all && rm -rf node_modules/ && yarn cache clean && yarn install && yarn start --reset-cache

The solution is, to delete the build folder @ /ios/build, then execute react-native run-ios solved it

Isaac
  • 12,042
  • 16
  • 52
  • 116
2

For others with the same problem on iOS with CocoaPods:

I tried all of the solutions above, without luck. I have some packages with native dependencies in my project, and some of those needed pod modules being installed. The problem was that React was specified in my Podfile, but the React pod didn't automatically get upgraded by using react-native-git-upgrade.

The fix is to upgrade all installed pods, by running cd ios && pod install.

brkn
  • 646
  • 5
  • 11
2

The fix we did was to make sure the ANDROID_HOME and PATH variables were set up prior to the build.

First, run the below two commands then the build the app for the device.

export ANDROID_HOME=/Users/username/MyFiles/applications/androidsdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Saif Kamaal
  • 192
  • 1
  • 9
2

Expo users - make sure your app.json sdk version and package.json expo version are (may be equal) compatible to each other.

ascripter
  • 5,665
  • 12
  • 45
  • 68
cherankrish
  • 2,004
  • 1
  • 16
  • 11
2

This is working for me :

react-native start --reset-cache
Parveen Chauhan
  • 1,396
  • 12
  • 25
1

I also had this issue using Expo and iOS Simulator. What worked for me was erasing the Simulator in Hardware > Erase All Content and Settings...

catico
  • 98
  • 2
  • 9
  • I am pretty sure that this can be accomplished by just uninstalling the Expo app from the emulator. No need to everything. – Ajay Gupta May 20 '18 at 13:24
1

I have got the same issue while building my react native app for android and I did the following which worked for me.

The "JavaScript version 0.50.1" in the error console is the react-native version in your package.json file. Make sure it is the same version as "Native version 0.50.0" in the error console.

  1. I have Updated the react-native version to the "Native Version 0.50.0" as prompted in the error console.
  2. Rebuild the app react-native run-android.
1

Possible Fix:

  1. Delete the package-lock.json
  2. Run: watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/haste-map-react-native-packager-* && rm -rf node_modules/&& npm install

If the problem persists, try to execute the project directly from the Xcode

This worked for me.

Alejo
  • 21
  • 1
  • 5
1

In my case (NOT using expo & Android build)

package.json

"dependencies": {
    "react": "16.3.1",
    "react-native": "0.55.2"
}

And app.json

{
  "sdkVersion": "27"
}

resolved the issue

Ajitsen
  • 338
  • 3
  • 7
  • This is true especially if you're using Expo. Check out Expo's upgrade docs for more info: https://docs.expo.io/versions/latest/workflow/upgrading-expo-sdk-walkthrough/ – blakeface Jul 13 '19 at 14:29
1

I was trying to build and run a React Native app from WebStorm and ran into this problem. The simple solution for me was:

watchman watch-del-all

On macOS, if watchman is not already installed, install it using Homebrew:

brew install watchman
friederbluemle
  • 33,549
  • 14
  • 108
  • 109
1

In my case, I changed the expo version manually. I got the same issue because I forgot to update sdkVersion in app.json and babel-preset-expo in package.json

After that run: expo r -c to clear cache and start the app.

Giang Phan
  • 534
  • 7
  • 15
1

This Answer is Published in 2020, Fix this Error in 3 steps:

First step: I changed the value of expo in package.json file to the latest supported version, according to expo documents(visit here).

Second step: I changed the value of sdkVersion in app.json file to the same value of expo in package.json.( equal number to last step).

Third step : I changed the value of react-native in package.json file to the same value of React Native Version , according to expo documents(visit here).

now your ready to go.

use npm install to install specified version of dependencies and then npm start to run the project

sina
  • 2,103
  • 1
  • 19
  • 26
  • Thanks! This worked for me 18/06/20 - i used SDK version 38 for steps 1 & 2 and then "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.1.tar.gz", for step 3 – Ash Hogarth Jul 18 '20 at 15:53
1

I got this classing when TypeScript type definitions mismatched.

E.G react-native at 0.61.5 in dependencies and @types/react-native at 0.60.0 in devDependencies.

As soon as I updated devDependencies it worked. Didn't have to restart anything.

Thomas Hagström
  • 4,371
  • 1
  • 21
  • 27
1

edit your package.json for your javascript version

"react-native": "^0.50.1",

after run

npm install
Ferhat KOÇER
  • 3,890
  • 1
  • 26
  • 26
1

For me, who is running with a monorepo, there was a hidden react-native version inside yarn.lock. It was not present in any package.json, but was never deleted.

I removed that particular react-native version from yarn.lock, and did a

yarn install

This cleaned out alot of old stuff and made sure that things was working fine.

vonGohren
  • 929
  • 8
  • 22
1

for my problem fix this when change emulator with API Level below 28. this source of problem because of network changes in API Level 28 and above. fix this problem by add

<application
     android:usesCleartextTraffic="true"

to androidManifest.xml

AliTN
  • 96
  • 5
0

This is not a fix, but in my case, I had multiple RN apps installed on my device and I was unknowingly attempting to 'Reload` from within the wrong application. (I'm developing two apps simultaneously at the moment) So make sure you're in the correct application!

Friendly-Robot
  • 1,124
  • 14
  • 24
0

Try changing the version of your react-native specified in your package.json (under dependencies - react-native) to the same as 'Native Version' shown in the error message. Then run 'npm install' again.

Pnar Sbi Wer
  • 468
  • 6
  • 9
  • any idea how to downgrade to the version mentioned in the package.json? – HungrySoul May 16 '18 at 05:50
  • in your package.json you should see something like "react-native": "^0.55.0" under "dependencies". Change that number (0.55.0 in this example) to your desired version and run "npm install" again. – Pnar Sbi Wer May 28 '18 at 05:38
0

Make sure also that the wifi is enabled in your emulator

0

Opene projectdir/android/app/build.gradle

Try:

compile("com.facebook.react:react-native:0.51.0") { force = true }

Instead of compile "com.facebook.react:react-native:0.51.0" { force = true }

Ref.: Link

Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52
0

In my case, my android physical device does not connect to the js server running on my development machine. So i have to manually set the debug server host & port on my android device.

Gamz Rs
  • 311
  • 5
  • 9
0

This would be especially applicable for Android Studio 3.2 or newer users, as this did not seem to happen before upgrading.

If you didn't change the version of React Native in your configuration (package.json, build.gradle), the problem with the version mismatch could come from undetected changes to project files after checking out another commit in git. To overcome that, make sure to:

  • Clean the build: Build > Clean Project

  • Sync Project with Gradle files: next to the Stop button on navigation bar

  • Make Project: first button in navigation bar with an hammer icon

  • And finally Run / Debug app

This would also overcome the Session 'app': Error Installing APK error that might happen due to Instant Run once the app is uninstalled from the device.

Siavas
  • 4,992
  • 2
  • 23
  • 33
0

Close the nodejs terminal and Rebuild.

Ashutosh Dash
  • 602
  • 2
  • 7
  • 15
0

I was able to fix this by deleting node_modules and running npm install again

Dazzle
  • 2,880
  • 3
  • 25
  • 52
0

I update the react-native version: 0.57.4 to 0.59.8 and i getting the following message "React-Native Version Mismatch"

This solution works for me:

1.- In the folder of the project, update all the code react-native in the Android Studio:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

2.- Go to Android Studio and FILE->>INVALIDATE CACHES/RESTART
3.- In Android Studio, BUILD->>CLEAN PROJECT
4.- In Android Studio, BUILD->>REBUILD PROJECT
5.- Delete App in simulator or Devices
6.- Run...

I hope to help you!

Ing Rico
  • 31
  • 1
0

All those answers about changing versions to match whatever were wrong for me.

What the error does not tell you is where that version is coming from. Running a search of all files, I found that there was only 1 place where the javascript version was defined: The problem was that the bundle (\android\app\src\main\assets\index.android.bundle) needed to be regenerated as it was containing older versions compared to the installed bundle.

In order to regenerate that file, I had to run the following command:

react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

And because I had upgraded my react-native, running this command gave me a few errors I needed to resolve (mainly installing new dependencies).

Clearing cache, reloading in android studio, reloading react, reloading the terminal, creating a new project and transfering the files, running watchman, all did not work as that specific bundle file happens to be tracked in the Git repo.

FMaz008
  • 11,161
  • 19
  • 68
  • 100
0

This worked for me

expo update 39.0.0 --npm

As my expo version was 38(Check in package.json).

Shreya B
  • 305
  • 2
  • 14
0

I found an answer from stackoverflow another question and I like to place it here.

First step: I changed the value of expo in package.json file to the latest supported version, according to expo documents(visit here).

Second step: I changed the value of sdkVersion in app.json file to the same value of expo in package.json.( equal number to last step).

if sdkVersion not exists in your app.json file, please add it like this. "sdkVersion": "xx.x.x" (same as expo version in package.json)

Third step : I changed the value of react-native in package.json file to the same value of React Native Version , according to expo documents(visit here).

Rajitha Udayanga
  • 1,559
  • 11
  • 21
  • "✔ Removed deprecated sdkVersion field from app.json." sdkVersion is deprecated as of now (Expo44) – mixdev Mar 23 '22 at 04:58
0

Delete your application from your device and then install it again

0

I've had this issue after manually updating my packages. Removing all projects from the Expo Go app and running expo update fix the problem automatically for me.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
0

Installing a new emulator and closing all terminals used to work for me and only when I ran from Android Studio. Now that's not working anymore.

A bit counterintuitive but I noticed that when I ran from Android Studio received that error the metro bundler terminal wasn't launching.

enter image description here

So I executed npx react-native run-android from terminal (which didn't work but it did launch the metro bundler) , then I ran that app from Android Studio and it worked!

enter image description here

sigmapi13
  • 2,355
  • 3
  • 30
  • 27
0

Close js Server terminals and run build again

Paresh Chavda
  • 340
  • 1
  • 4
  • 11
-1

I updated the SDK version in app.json to match with the react native SDK version in package.json to fix this issue

In app.json

"sdkVersion": "37.0.0",

In package.json

"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
-1

For me, I had to open multiple node js terminal for react native and forgot to close before running app into my android device. I close the terminal and run again and it loaded the page successfully

Quick learner
  • 10,632
  • 4
  • 45
  • 55