React Native Version Mismatch

2019-01-13 01:50发布

问题:

Getting the following message when i init a new project and then launch the x-code 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?

Thanks!

回答1:

This is what I've done with it:

Close all terminals and run build again.

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

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



回答2:

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
  }
}


回答3:

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



回答4:

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



回答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



回答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.)



回答7:

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



回答8:

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.



回答9:

Try installing the dependencies again. That worked for me-

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



回答10:

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.


回答11:

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.



回答12:

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.



回答13:

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



回答14:

For me, I had to restart my computer, open the IDE(VS Code, Brackets, Sublime, etc) again and build the project



回答15:

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...



回答16:

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!



回答17:

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.



回答18:

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.


回答19:

Make sure also that the wifi is enabled in your emulator



回答20:

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



回答21:

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

  1. Uninstalling the app
  2. lsof -i :8081
  3. kill -9 PID
  4. Rebuild the app react-native run-android


回答22:

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



回答23:

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.



回答24:

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.



回答25:

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



回答26:

My solution is

  1. Upgrade React-Native

  2. Delete all node_modules

  3. Modify package.json (react native with latest version)
  4. NPM install