While building a react-native app, we sometimes encounter an error that says:
Unable to resolve module `AccessibilityInfo`: Module does not exist in the module map
So, what is the cause of this error and how do we solve it?
This error is due to the version of react-native used. Most likely, you are using react-native 0.56.0, which has this bug.
The solution is hence simple- to upgrade the react native version.
There are multiple ways to do this, so let’s look at two of them.
package.jsonlocated at your project root directory.
- In the
dependenciesblock, you will see react and react-native. Change the react version to 16.5.1 and the react-native version to 0.57.0.
- In your terminal, run
npm install, which will install the new versions of react and react-native.
- Next, run the command
react-native upgradeand enter ‘y’ whenever prompted for a file replacement.
Upgrading from the Terminal
- In the terminal, make sure your working directory is the project root directory. Use following commands to upgrade react and react-native respectively:
$ npm install --save email@example.com
$ npm install --save firstname.lastname@example.org
react-native upgrade and enter ‘y’ whenever prompted for a file replacement.
Your react and react-native should have been upgraded to the respective versions, and you can now run
react-native run-android to see that the error due to the AccessibiltyInfo module has vanished.
Note: In case you get the following error:
Execution failed for task ':app:compileDebugJavaWithJavac'.
/android/app/src/main/java/com and make sure the location consists of only one directory containing the MainActivity.java and MainApplication.java files.
In case you have two, check the one that was created when you used the command react-native upgrade. That is the one you want to keep. Delete the other one.
Also, open your AnroidManifest.xml file, located in
/android/app/src/main and make sure the package at the top of the file is com.<directory> where <directory> is the directory containing the two .java files.