88

I am getting RNSScreen error even though I have installed all related packages and followed react-navigation guide (https://reactnavigation.org/docs/getting-started#installation) but nothing worked for me.

enter image description here

enter image description here

enter image description here

Amit Agrawal
  • 1,059
  • 2
  • 9
  • 14
  • 3
    Please add code and data as text ([using code formatting](//stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](//meta.stackoverflow.com/a/285557). Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. – cigien May 01 '21 at 23:39
  • See this answer https://stackoverflow.com/a/67956805/3437900 – Shiva Jun 13 '21 at 09:40
  • I have this issue on my android version only. I have been through all of your suggestions above without any luck. Please take a look at my question with a full description here: https://stackoverflow.com/questions/70007180/rnsscreen-was-not-found-in-the-uimanager-android-only – Simon Degn Nov 21 '21 at 21:12

31 Answers31

86

Faced the same issue while implementing Navigation. Run following commands

npm install @react-navigation/native

React Navigation is made up of some core utilities and those are then used by navigators to create the navigation structure in your app.


In your project directory, run:

npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view

This will install versions of these libraries that are compatible.

If you're on a Mac and developing for iOS, you need to install the pods to complete the linking.

npx pod-install ios

Now run


react-native run-ios
Gurjinder Singh
  • 9,221
  • 1
  • 66
  • 58
25

That usually happens when you install all packages to add navigation without terminating the running build. Make sure to stop the running process for ( android or IOS ) then run it again after installing them and adding the routing components

Mohammed Ramadan
  • 655
  • 7
  • 10
18

I think you are missing to install react-native-screens components. That is required part in install react navigation guideline.

Dont forget to run pod install in ios folder after install package from npm.

Dat Ho
  • 694
  • 3
  • 10
  • I have already installed it as mentioned in the documentation but did not work. For more information, I am using a windows machine and Android AVD Manager. – Amit Agrawal Apr 03 '21 at 08:09
  • If you are building for Android, I think you should run `npx jetify` after install package – Dat Ho Apr 04 '21 at 09:22
16

stop all the terminal servers and then run

npx react-native run-android

if it still does not work,

npm i react-native-screens

and then

npx react-native run-android
kaizen
  • 1,132
  • 1
  • 14
  • 20
  • First Uninstall the package using: npm uninstall react-native-screens Then Install it again npm install react-native-screens – Man Oct 13 '22 at 09:24
12

This solution (source) always works for me, here is the exact solution:

TLDR; This happens when you install packages to add navigation without terminating the running build of the app.

Step-by-step:

If you're facing with this error

Invariant Violation: requireNativeComponent: "RNSScreen" was not found in the UIManager.

Follow these steps:

1. Make sure in your `package.json` file if you have the following packages:

  • @react-native-community/masked-view
  • @react-navigation/native
  • @react-navigation/stack
  • react-native-gesture-handler
  • react-native-reanimated
  • react-native-safe-area-context
  • react-native-screens

2. Next ensure if you have pods up-to-date (For iOS only) by making sure cd ios --> pod install --> cd ..

3. And finally cancel the current build by pressing Ctrl+C (twice/thrice) and then do npx react-native run-ios

Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116
9

Close Metro and run npx run android to rebuild your code

web_walkerX
  • 840
  • 10
  • 19
9

RNSSCreens error because the react-native-screens isn't installed on the your project

just run npm install react-native-screens react-native-safe-area-context or if your using yarn run 'yarn add install react-native-screens react-native-safe-area-context'

6

This was happening to me on both iOS and Android. I managed to get Android working again by updating the package:

"react-native-screens": "^3.18.1"

Then adding this to dependencies in: android/app/build.gradle

implementation project(':react-native-screens')

Then adding this to protected List getPackages() in: android/app/src/main/java/com/myapp/MainApplication.java

@Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
  packages.add(new com.swmansion.rnscreens.RNScreensPackage());
  return packages;
}

NOTE: Make sure you don't already have an import for com.swmansion.rnscreens otherwise the app will keep rebooting due to duplicate screen views

Then finally adding this to android/settings.gradle

include ':react-native-screens'
project(':react-native-screens').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screens/android')

Make sure you clean gradle before running the app, for example navigate to android folder and run:

./gradlew clean

As for iOS, just add this to target 'myapp' do in: ios/Podfile

pod 'RNScreens', :path => '../node_modules/react-native-screens'

Make sure you delete your Podfile.lock and then run pod install --repo-update in your iOS folder before running the app.

Mark Lanham
  • 576
  • 5
  • 7
4

As I don't have enough reputations to upVote the answer, I am mentioning the answer which worked out to me here Solution mentioned by @Gurjinder Singh , worked smoothly..

Recapturing:

Issue : With Expo, Sanity.io app was working on device in dev, but once apk was generated using "eas build -p android --profile preview" , build was successful but when I tried opening the app in my mobile, after splash screen app was crashing.

Adblogcat showed : com.facebook.react.common.JavascriptException: Invariant Violation: requireNativeComponent: "RNSScreen" was not found in the UIManager.

Solution worked:

npm install @react-navigation/native

npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view

thanks to community and @Gurjinder Singh (top voted)

vasista k.j
  • 51
  • 1
  • 1
  • 4
4

Happy Update: react-native-screens 3.18.2 is out with a fix for this, if you were impacted by the 3.18.1 release that caused compile problems (which you can check by seeing the message below, if needed)

So, mostly obsolete now answer preserved below, but just updating packages should get you moving. Cheers


Nowadays if this is happening it is because react-native-screens 3.18.1 includes new configuration that is only compatible with react-native 0.69+

If you are using an older react-native you need to make sure your react-native-screens dependency is exactly 3.18.0:

  "react-native-screens": "3.18.0",

then likely a npx react-native start --reset-cache to restart your javascript bundler with a fresh cache.

You will know if this is your problem if you see something like this when you say npx react-native run-android:

warn Package react-native-screens has been ignored because it contains invalid configuration. Reason: "dependency.platforms.android.componentDescriptors" is not allowed

There may be a 3.18.2 soon with a fix - reference: https://github.com/software-mansion/react-native-screens/issues/1614#issuecomment-1276245207

Mike Hardy
  • 2,274
  • 3
  • 25
  • 57
  • For those who had this warning recently, I just had it and only locking version "react-native-screens": "3.13.0" did the trick for me, but if you want the complete answer, this is the one ! – yaken Oct 14 '22 at 03:32
3

Hey i was also facing same problem . Just use

npm install react-native-screens

.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
2

I've encountered the same problem, and solved it.

You can just close the terminal and app on Android Emulator(or device), and just run npm run android or react-native run-android again.

I think they might have some cache and occur the error.

I hope you can fix the problem.

2
  1. Close the Metro and IOS simulator.
  2. Ensure you go to your ios folder run pod install
  3. Reopen your simulator

This should solve the problem. I also use quite a while to figure it out

TeckBeng
  • 27
  • 8
2

I worked on this problem for several days and this is want worked for me:

In the android\app\src\main\java(your project name)\MainApplication.java

add to Imports:

import com.swmansion.rnscreens.RNScreensPackage;

Then add new RNScreensPackage() to the ReactPackage List:

@Override
    protected List<ReactPackage> getPackages() {       
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),  
            ...
            new RNScreensPackage()
      );
    }

Edit: This was after I tried everything else here.

coolj63
  • 31
  • 2
1

This helped me. install this package

npm i react-native-screens

and add

import { enableScreens } from 'react-native-screens';

enableScreens();
Ragul CS
  • 417
  • 3
  • 11
1

You go into the ios folder of your project folder and run the following command.

pod install

Then run the simulator.

1

You must have react-native-screens installed and I'm guessing that you have done it. So, I will just you a Problem that maybe is not really clear in the documentation.

So you probably just Install React Navigation on your app.

Once you installed it, you need to restart you app.

So close your app, run react-native run-ios or react-native run-android again.

React navigation Install some native modules. Thus, you need to restart that app as I mention.

This is really clear on their documentation.

Oximer
  • 548
  • 5
  • 19
1

I also came across the same problem. For Android, I uninstall the app from the emulator then build the app again.Problem solved. Assuming that you already installed packages you need.

fatih511
  • 21
  • 3
1

Just stop running your node server and build the app again from Xcode/Android Studio or using command react-native run-ios or react-native run-android

1

In case you are on android, you need to rebuild using npx run android or react-native run-android The new installed apk will work fine

Abhishek Mathur
  • 478
  • 5
  • 12
1

I also get this error and after doing these steps my app starting running

  1. cd android
  2. ./gradlew clean (for windows or linux)
  3. npm install react-native-screen
  4. react-native start & react-native run-android
Bilal Yaqoob
  • 790
  • 1
  • 10
  • 22
1

worked for me yarn add react-native-reanimated

"@react-navigation/native": "^6.0.10", "@react-navigation/native-stack": "^6.6.2", "react": "17.0.2", "react-native": "0.68.2", "react-native-reanimated": "^2.8.0", "react-native-safe-area-context": "^4.3.1", "react-native-screens": "^3.13.1", "styled-components": "^5.3.5"

Muhammad zubair
  • 106
  • 1
  • 7
0

Finally found the solutions, first by creating new project and secondly re-setup of the react-google-maps library.

Workaround Solution: Created new project, installed all dependencies from scratch, followed step-by-step installation guidelines of react-native screens, and finally moved all my code files into a newly created project. This worked for me :D

After digging into the project code and compared project code with newly generated code, here are my findings:

Actual Problem: We had integrated react-native-google-maps library some time ago, for which I and other developers followed step-by-step guidelines and made changes in the MainActivity.java file in the android folder. There were some misconfigurations due to which RNSScreen issue was getting thrown.

Actual Solution Removed react-native-google-maps completely (uninstalled npm packages) and removed Google Maps configuration and did set up the react-google-maps library again

In conclusion, if any of the developers, try to set up google maps in react native, please check the version of react native and react-native-google-maps library and then follow the steps carefully.

Hopefully, this would answer your queries.

Amit Agrawal
  • 1,059
  • 2
  • 9
  • 14
0

In my case, the following code block helped!

npm install react-native-screens
npm run android/ ios
Showrin Barua
  • 1,737
  • 1
  • 11
  • 22
0

(It Workes For Me..!)

for React-native developers.. Some times the changes of packages Not reflacted in xcode so follow this steps for Solution..

Open Project in xcode -> Clean Buid Folder -> (Rebuid Your Project)Run on any Simulator and wait for Build.. ->Once Build either You can run again by Terminal or continue work by xcode..

0

none of the recommended answers worked until I tried what I found in this comment plus restart my steps:

  • deleting the node_modules directory
  • turn Metro and actually quit the simulator completely
  • yarn to install again
  • start metro via npx react-native start
  • install pods via npx pod-install ios
  • run simulator again via npx react-native run-ios
ariel guzman
  • 590
  • 7
  • 11
0

Make sure the below plugin install and linked with android & ios?

npm install react-native-screens

If not linked then perform the below command

react-native link react-native-screens

after successfully linked for android and ios, "Sync Gradle" from android studio and "pod install" for ios

Now close the terminal and again build and run app

Vishal Gadhiya
  • 450
  • 1
  • 6
  • 21
0

I updated Expo to 45.0.0. That fixed the error and solved a problem with the app crashing after launch in production mode but working fine on device with QR code or simulator.

Larry Feldman
  • 39
  • 1
  • 8
0

You need to do a few things:

  1. Open android/app/src/main/java/MainApplication.

  2. Replace the function getPackages() with:

    @Override protected                                                        
    List<ReactPackage> getPackages() {
    @SuppressWarnings("UnnecessaryLocalVariable")List<ReactPackage> packages = new PackageList(this).getPackages();
              // Packages that cannot be autolinked yet can be added manually here, for example:
              // packages.add(new ReactNativeFirebaseAuthPackage());
              return packages;
            }
    
  3. yarn start --reset-cache or npm start -- --reset-cache

  4. Clean:

     cd android
    ./gradlew clean
    
Nick K9
  • 3,885
  • 1
  • 29
  • 62
Khalil
  • 1
  • 1
0

A rather important step that I didn't see mentioned here, was that if you're an expo developer using a dev-client, you would have to rebuild your dev-client. To that end, these are the steps I followed to resolve this issue:

  1. Stop your metro server.

  2. Run this in the terminal to install the required dependencies:

npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-masked-view/masked-view
  1. Add the reanimated plugin to the babel.config.js file, ensuring it's the last one listed. These is what my own babel.config.js file looked like
module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      [
        "module-resolver",
        {
          extensions: [".tsx", ".ts", ".js", ".json"],
        },
      ],
      "react-native-reanimated/plugin",
    ],
  };
};
  1. Should be optional: delete node_modules directory and run npm install

  2. Not Optional: Run npx expo install --check to fix all dependencies that are not compatible with the installed expo SDK.

  3. Head to your emulator and uninstall your dev-client.

  4. Rebuild your dev-client using whatever command is best suited for your use case. You can find specific instructions here

  5. Restart your emulator

  6. Reinstall the dev-client

  7. Run expo r -c to clear the cache while running

You're good to go!

-1

Actually The Solution Is Very Simple.

You will however need to add some dependencies yourself: open android/app/build.gradle and add the following under dependencies:

Past The Follwing 2 Line Code.

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
Talha Abid
  • 11
  • 2