undefined is not an object (evaluating 'RNGestureHandlerModule.State' - react-native

I have installed react-navigation in my React Native project. Its a starter project doesn't have any codes. But while running project I am facing error like this.
Here is my Navigation code
import { createStackNavigator } from 'react-navigation';
import Home from './screens/Home';
import WeatherDetail from './screens/WeatherDetail';
const Navigation = createStackNavigator({
Home: { screen: Home },
WeatherDetail: {
screen: WeatherDetail
}
});
export default Navigation;
And here is the App.js codes
import Navigator from './Router';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Navigator />
</View>
);
}
}
If I remove the navigator component from the App.js and replace it with a Text the application runs without any error.

remove node_modules and package-lock.json
npm install
npm install --save react-navigation
npm install --save react-native-gesture-handler
react-native link

If you are using react-link to link your dependencies:
0pen your ios Podfile and delete all yout linked dependencies: pod 'xxxxxxx', :path => '../node_modules/xxxxx
Close Xcode
In your /ios folder run "pod update"
In your project source run "react-native link"
Open Xcode and Clean Build Folder from Xcode Menu -> Product
Run your application from Xcode
Link manually the dependency "react-native-gesture-handler" into your Xcode Project following steps in documentation: https://facebook.github.io/react-native/docs/linking-libraries-ios
Now run your application from Xcode, you should be fine.

From the official doc:
If you're on React Native >= 0.60, you need to disable autolinking for react-native-gesture-handler first. To disable autolinking for it, create a react-native.config.js file in the root of your project with the following content:
module.exports = {
dependencies: {
'react-native-gesture-handler': {
platforms: {
android: null,
ios: null,
},
},
},
};
If your are using React 0.60, just omit this official doc. Follow following steps:
rm react-native.config.js if exist
react-native link react-native-gesture-handler
cd ios && pod install && cd ..
react-native run-ios

I get the same error on ios from RN v0.60
The following worked for me:
cd ios
pod install

First, remove node_modules and package-lock.json and run npm install.
After installing the react-navigation package in your React Native project. You should install react-native-gesture-handler. If you’re using Expo you don’t need to do anything here, it’s included in the SDK. Otherwise:
npm install react-native-gesture-handler
And finally, link gesture dependency as:
react-native link react-native-gesture-handler
This answer based on the React Navigation document.

maybe someone come here because same problem as me.
i got this error because i'm using react-navigation version 3.x, in that version stackNavigator is change to createStackNavigator and should use createAppContainer(createStackNavigator)
im fix it just like mr.amiri said but im not delete my node_module im just follow step 3 - 5

Since I am not allowed to comment, I am posting it here. This is the answer by #Amiri Houssem but I am adding one more thing:
remove node_modules and package-lock.json
npm install
npm install --save react-navigation
npm install --save react-native-gesture-handler
react-native link
If there is an error even after these 5 steps, check android/settings.gradle and change that line to this:
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')

I'm answering because none of the above answers were relevant to me.
I got this error because VSCode automatically inserted import { TouchableOpacity } from 'react-native-gesture-handler' as a dependency in my file when I added a <TouchableOpacity> element.
Give the last files you edited a once-over just in case there's an import statement you don't expect!

I used this in the CLI to solve the issue
cd iOS
pod install
cd ..
react-native unlink react-native-gesture-handler

Uninstalled the app from the device and run the android project - react-native run-android and it worked fine

you can check your version of react-native
if React Native 0.59 and lower you can
react-native link react-native-gesture-handler
and check your #react-navigation version in
https://reactnavigation.org/versions

may be its late.
Temporary solution downgrade the version of react navigation:
1- unlink and uninstall react-navigation and the handler
2- add "react-navigation": "^2.18.2" to package.json
3- remove node_modules folder
4- npm i
5- react-native link

if you have done the above, it hasn't run yet, try this
if you use Windows
cd android
.\gradlew cleanBuildCache
and try running it
react-native run-android

Even though react-native-gesture-handler is present in node_modules folder, we need to add it to path or install it again. Then link with native code.
1) npm install --save react-native-gesture-handler
success Saved 1 new dependency.
info Direct dependencies
└─ react-native-gesture-handler#1.0.15
info All dependencies
└─ react-native-gesture-handler#1.0.15
2) react-native link
rnpm-install info Linking react-native-gesture-handler ios dependency
rnpm-install info Platform 'ios' module react-native-gesture-handler has been
successfully linked
rnpm-install info Linking react-native-gesture-handler android dependency
rnpm-install info Platform 'android' module react-native-gesture-handler has
been successfully linked
3) react-native run-android or react-native run-ios

If you are using a configuration with Podfile in ios. Follow this steps:
Comment this line pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler' in <react-native-project>/ios/Podfile.
Open <react-native-project>.xcworkspace Add RNGestureHandler.xcodeproj in Libraries (Right click over library folder and select "Add files to ") from node_modules/react-native-gesture-handler/ios.
Add libRNGestureHandler.a in (Build Phases) -> (Link Binary With Libraries).

This worked well for me as well.
1) npm install react-navigation
2) npm install react-native-gesture-handler
3) npm intstall
4) react-native link
uninstall the app
5) react-native run-android

Execute the following commands in command prompt (Run as Administrator)
npm install react-navigation
npm install react-native-gesture-handler
npm intstall
react-native link
Re-Install the application will resolve the issue.

I struggled with this and none of the above answers worked for me. Here's what I had to do:
Delete your ios folder entirely.
Delete your node_modules folder and package-lock.json.
Restart your computer.
Run react-native eject to re-create your native code folders.
Run npm install
Run react-native link
Run npm run start -- --reset--cache
Now run react-native run-ios

see your native react version, if version 0.60 then you must migrate to androidX using a jetifier, follow the steps in this link
https://github.com/mikehardy/jetifier
successful for me :)

If you're on React Native >= 0.60:
You should see the following entry in your ios/Podfile:
pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
If this line is not there, first run:
react-native link react-native-gesture-handler
ios/Podfile should now contain a new entry.
Now run this command from iOS directory /ios/:
pod install
Run your iOS project again either directly using XCode or react-native run-ios

Related

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

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.
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
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
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.
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
Close Metro and run npx run android to rebuild your code
This solution (source) always works for me, here is the exact solution:
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/stackreact-native-gesture-handlerreact-native-reanimatedreact-native-safe-area-contextreact-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
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'
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)
Hey i was also facing same problem . Just use
npm install react-native-screens
.
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.
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
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.
Close the Metro and IOS simulator.
Ensure you go to your ios folder run pod install
Reopen your simulator
This should solve the problem. I also use quite a while to figure it out
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.
This helped me. install this package
npm i react-native-screens
and add
import { enableScreens } from 'react-native-screens';
enableScreens();
You go into the ios folder of your project folder and run the following command.
pod install
Then run the simulator.
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.
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.
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
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
I also get this error and after doing these steps my app starting running
cd android
./gradlew clean (for windows or linux)
npm install react-native-screen
react-native start & react-native run-android
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"
you must clear the Metro bundler cache
run the following command :
expo start -c
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.
In my case, the following code block helped!
npm install react-native-screens
npm run android/ ios
(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..
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
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
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.
You need to do a few things:
Open android/app/src/main/java/MainApplication.
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;
}
yarn start --reset-cache or npm start -- --reset-cache
Clean:
cd android
./gradlew clean

RNCAndroidDropdownPicker was not found in the UIManager

I have installed nativebase version 2.15.2. I am getting following error in android:
requireNativeComponent "RNCAndroidDropdownPicker" was not found in the UIManager
I started getting this issue after installing the node modules on fresh install. After some research I resolved it by installing the package.
If you are using yarn for package installing
yarn add #react-native-community/picker
If you are using npm
npm install #react-native-community/picker
If you are using expo
expo install #react-native-community/picker
It's working for me:
npm install #react-native-picker/picker --save
Linking:
iOS:
cd ios && pod install
Android:
Clear and gradle run
The problem is with native-base version 2.x
Replace this:
import { Picker, Button, Container, Form, Item, Card, Text, Icon, Label } from 'native-base';
for this:
import { Picker } from '#react-native-picker/picker';
import { Button, Container, Form, Item, Card, Text, Icon, Label } from 'native-base';
Of course you need to install:
#react-native-picker/picker
yarn add #react-native-picker/picker
Tested in react-native >= 0.68.x
Just had the same issue with a fresh install (no expo) Simple fix for me was the usual suspects.
Reset the server & cache
npx react-native start --reset-cache
Remove node modules, clean, and build. Reinstall and run again.
rm -rf node_modules
npm i
cd android/
./gradlew clean
cd ../
npx react-native run-android

What is the problem with 'react-native-elements'?

When I try to use 'react-native-elements' package in my code, I face this error :
bundling failed: Error: Unable to resolve module react-native-vector-icons/FontAwesome from node_modules\react-native-elements\src\social\SocialIcon.js: react-native-vector-icons/FontAwesome could not be found within the project.
I have done many things to fix it. I installed the 'react-native-vector-icons' again, I used 'rm ./node_modules/react-native/local-cli/core/fixtures/files/package.json' but non of them worked. what should I do to overcome this problem? I really appreciate your help guys.
make sure that you've installed the package with
npm install react-native-vector-icons and link it through
react-native link react-native-vector-icons
then for ios you need to install pod (goto your project ios folder on terminal and enter command pod install)
and then reset packager cache with react-native start --reset-cache
if you are using react version <0.60 use react-native link react-native-vector-icons and do the steps link and if react version > 0.60 then cd ios && pod install && cd .. and try again if its not work delete the build folder and rebuild again.

Issue in React native Version 0.60 ->null is not an object ( evaluating 'RNGestureHandlerModule.Direction')

I'm using react-native-gesture-handler within react-navigation and getting this error
null is not an object ( evaluating 'RNGestureHandlerModule.Direction')
Workspace file is automatically created with new React native version(0.60). And there is no libraries under libraries folder in Xcode project.
I created new project in react native and new project created with react-native version 0.60 automatically. Then I installed following dependencies
npm install —save react-navigation
npm install —save react-native-gesture-handler
After installing I am getting runtime error
null is not an object ( evaluating 'RNGestureHandlerModule.Direction')
I also tried to manually link react-native-gesture-handler dependencies with following steps
Right Click Libraries "Add Files to Project"
/node_modules/react-native-gesture-handlers/ios/RNGestureHandler.xcodeproj
Go to build phases and add libRNGestureHandler.a
Run
After that I am getting following errors
-> File not found
-> File not found
Any suggestion for me to fix this?
Did you try using react-native link react-native-gesture-handler?
For me the solution was:
1) react-native link react-native-gesture-handler
2) cd ios
3) pod install
as now, pod is installed automatically into the project with react-native 0.60
If you use RN > 0.60 you don't have to link react-native-gesture-handler manually as it supports autolinking.
For iOS
cd ios && pod install
For further info see issue #671
Please try to link react-native-gesture-handler then fixed this error
try this command for link gesture-handler pluggin
react-native link react-native-gesture-handler

Android 'react-native-gesture-handler' error

When I follow the instruction by the react-navigation website : https://reactnavigation.org/docs/en/getting-started.html.
react-native link react-native-gesture-handler
and then change the MainActivity.java like it asks.
Then run react-native run-android, and error pop up :
error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:
react-native-gesture-handler (to unlink run: "react-native unlink react-native-gesture-handler")
This is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink " and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.
my react-native version :
react-native-cli: 2.0.1
react-native: 0.60.0
However, when I follow the instruction, to unlink the library
use : react-native unlink react-native-gesture-handler
The app successfully built, but now it pops up another error in the app :
null is not an object (evaluating 'rngesturehandlermodule.direction')
I tried a lot of solution in a lot of websites, like
undefined is not an object (evaluating 'RNGestureHandlerModule.State'
non of them is working for me
Looks like this is to do with the new autolinking feature in RN 0.60.
For iOS
To fix for now just add the following podspec for RNGesureHandler to ios/Podfile
pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
Then in the ios directory run pod install to install it.
For Android
Path: android/app/src/main/java/com/projectname/MainApplication.java
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
....
protected List<ReactPackage> getPackages() {
// Add additional packages you require here
// No need to add RnnPackage and MainReactPackage
return Arrays.<ReactPackage>asList(
....
new RNGestureHandlerPackage()
);
}
Have a good day.
I'm not sure about what went wrong, but very possibly because of the react-native-cli that upgraded from below 0.60.0 to above it.
BEFORE 0.60.0 when running react-native run-android, the command will run a metro packager, along with building the android app, and then run the app that connect to the metro packager.
That's why in the past, we only run one command "react-native run-android" to run the project.
But AFTER 0.60.0 when running react-native run-android, the command will only build the android-app, and run the app to connect to the metro packager.
I saw a command prompt blinked once, might also be how the command start the metro packager went wrong and the packager just closed itself somehow.
Also as for the problem with react-native link react-native-gesture-handler I believe it is the new feature of react-native 0.60.0 to autolink library, so manual linking of library is not necessary anymore. As a lot of the library provider might need to start providing auto-linking features, or might face the same error, not just react-native-gesture-handler.
Temporary Solution until someone fix the react-native-cli to run the metro packager again:
Open 2 command prompt instead of 1. And run the command below on each of the command prompt:
react-native start
react-native run-android
You might want to run the first command first and wait for it to be ready before running the 2nd.
Otherwise, you app might turn out to be blank.
Source : I tried it myself by creating new project and running the command as mentioned by the question.
What you can do is, first uninstall react-native-gesture-handler.
Then delete IOS and Android folder.
Then run below command.
1.react-native upgrade --legacy true // to recover ios and android folder.
2.npm install react-native-gesture-handler
3.react-native link
4.react-native run-android
5.react-native run-ios
Also update your MainActivity.java file , follow official website:
https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html
Did you run react-native run-android or react-native run-ios ?