React Native version mismatch error

Before starting this article, if you are in a hurry to solve the problem and have a good English, you can refer to this article: https://stackoverflow.com/questions/47763824/react-native-version-mismatch

First of all, the screenshot of the problem I encountered is as follows

As you can see, the prompt is very clear: React Native version mismatch

I have encountered this error once before. At that time, I saw someone else’s solution, which was to close all terminals or the command line window of the integrated development environment.

But today I encountered this problem again, and found that closing the command line window is useless, let alone closing the command line window, I even tried methods such as deleting node_modules and restarting the machine. Of course, including the prompt on the screen: Run

watchman watch-del-all && react-native start --reset-cache

This order.

None of these methods solved my problem, and the problem appeared very suddenly. It was the kind that ran well five minutes ago, but it's not easy to use now.

After going through various materials, I finally found the answer in this article: https://stackoverflow.com/questions/47763824/react-native-version-mismatch

In fact, the root cause of this error is as told to us in the prompt: React Native version mismatch,

However, there is no indication of the direct cause of this problem. At present, I have encountered this problem in two situations. I feel it is necessary to record this pit. I hope everyone can avoid detours.

Summarized as follows:

There are usually two situations in which this problem will be encountered

1. The first situation

It is also a relatively common situation: there are other projects with different RN version numbers running in development mode. At this time, if we run the project we want to debug with react-native run-android, this error will be reported. Intuitively, there are other command line windows running RN projects open. At this time, all we have to do is to close these conflicting command line windows, and the problem will be solved.

2. The second case

The second situation is that this problem occurs when the version of the RN library configured in the Android/iOS project is inconsistent with the version of the RN library configured in the JS project. In this case, the Android project only needs to configure the default configuration of the RN library under android/app/build.gradle from

compile 'com.facebook.react:react-native:+'

To:

compile ('com.facebook.react:react-native:0.54.3') { force = true } // 0.54.3 处变为自己的JS工程中的相应版本号
The problem can be solved.

The second situation usually happens suddenly. What I encountered today is the second situation. Of course, I also encountered the first situation. . . The reason for the second situation is that (for example, in the case of my personal encounter), the version number is not explicitly configured in gradle, but the'+' is used to specify the native version of react-native on the Android side, and the meaning of'+' Yes, use the latest version of the library. When we build a project, there is naturally no problem, because when we use commands to build a project, we usually default to the latest RN version when the project was created. It is natural to write this in the configuration file, but if our development cycle is very long, then such a configuration may have version mismatch problems. And it may appear suddenly.

The second case is less common than the first case, because it is possible that RN's Native repository may not be updated during our development cycle. But precisely because it is not common, the difficulty of troubleshooting naturally increases.

In fact, the above two situations   have been reflected in the answer to the question https://stackoverflow.com/questions/47763824/react-native-version-mismatch .

OK, I hope this article can help you solve the problem. Thank you.





Guess you like

Origin blog.csdn.net/awy1988/article/details/80336913