Invariant Violation: new NativeEventEmitter() requires a non-null argument - react-native

image
I am developing an ios app but i got dependency issues and
Invariant Violation: new NativeEventEmitter() requires a non-null argument. error
import { NativeModules, NativeEventEmitter } from 'react-native';
const razorpayEvents = new NativeEventEmitter(NativeModules.RazorpayEventEmitter);
NativeModules.RazorpayEventEmitter is empty .

Go to ios folder then remove
Pods & Podfile.lock
run pod install
Rebuild project
And make sure you have followed the installation instruction correctly.
Drawer Installation
I hope it can solve your issue.

I used drawer navigation in my react app and then faced same issue.
Go to ios directory and say pod install.
Rebuild your application.
This solved my issue.

I have added below line in my .zshrc file:
export LANG=en_US.UTF-8
and then i ran command
source .zshrc
to save the changes in .zshrc file.
then did pod install and it worked.

npm i (check if you have any failed dependency downloads and user either --force or --legacy-peer-deps)
cd ios && pod install
cmd + shift + k and re-run your app!

Related

Trying to import realm, but getting error: Missing Realm constructor. Did you run "pod install"? (I'm using windows)

I'm making a mobile application with react native.
I want to use Realm (mongodb).
So after running:
npm install realm
realm was correctly added in the "node_modules" and I tried to import realm with:
import Realm from "realm";
If I do npm start and test the app, I get to following error message:
Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
I'm using windows and testing the app on an android device. Earlier questions about this matter on the internet suggested it is in my situation not needed to do "pod install".
I also tried to autolink realm, with:
react-native link realm
But then I get the warning:
warn Calling react-native link [packageName] is deprecated in favor of
autolinking. It will be removed in the next major release. Autolinking
documentation:
https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
(node:26016) Warning: Accessing non-existent property 'padLevels' of
module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created)
Does that mean that the autolinking is not successful, because autolinking will be removed in the next release?
Does any of you have suggestions on how I can successfully import Realm in my react native project?
Here are some of the dependency versions:
"expo": "^44.0.0",
"realm": "^10.14.0"
"react-native": "0.64.3",
Add this package:
npm install realm#hermes
Works for me.
run this command:
expo run:android
you must build your project first
and remember realm is working only on production environment
As the error message suggests, you need to install the pod files for realm to work with iOS. Those are the steps:
In your project folder run npm install realm. It adds the npm package to your react native project
In your iOS folder (cd ios) run pod install. It gets all iOS realm libraries and compiles the iOS-part of your npm package and creates the .xcworkspace.
Add the import to your component: import Realm from "realm";
Switch back to your project folder and run your project: react-native run-ios
Hope that solves your problem!

Requiring unknown module "1". If you are sure the module exist, try restarting Metro

Does anyone experience this issue?
After pointing to the default page in index.js, an error occurred with the following error code:
Requiring unknown module "1". If you are sure the module exist, try restarting Metro.
The screenshot:
And here's the exact code from index.js:
import {AppRegistry} from 'react-native';
import App from './src/components/LoginPage';`// import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
And my landing page:
Found the answer here
Basically it asks you to terminate the processes running on a specific port.
Run the following command to find the id for the process that is listening on port 8081:
$ sudo lsof -i :8081
Then run the following to terminate the process:
$ kill -9 <PID>
Try to remove 'node_modules' folder and re-install modules with yarn or npm install
I hope it's can help you
This is my solution. It works for me. go through the following steps. check the emulator or your device reloading at each of the steps whether it is work or not.
wipe out your emulator or delete the app from your device and run it again.
run nmp install in your terminal and then restart metro bundler by running react-native start.
run your app in react native CLI -> npx react-native run-android or in expo CLI -> expo start.
cheers!
This problem can be faced from multiple sources. The one I faced was with Stack Navigation I used in my case.
It was use of 'react-native-gesture-handler' and 'react-native-reanimated' here.
For that we need to do 2 things without fail -
Adding import 'react-native-gesture-handler'; as the very first line in wither index.js or App.js which ever present in code.
Adding plugins: ['react-native-reanimated/plugin'], in bable.config.js along with presets there.
try npx react-native run-android or react-native run-ios to rebuild and install app.
TLDR:
If you are using yarn, switch to npm.
I used yarn before and used to get this error at almost every change I did to the app. I have used npm on other projects without having these headaches so decided to switch back to npm just to try and it worked. I still get the error when I introduce bigger changes to the app like reorganizing navigation or installing new packages, but that's it.
Just close the server and open it again
That solved to me

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.

BVLinearGradient was not found in the UIManager?

There is documentation about this, but it is for macOs only. https://github.com/react-native-community/react-native-linear-gradient.
I linked the library by running npm install react-native link react-native-linear-gradient.
I don't understand this i dont have a ios folder, i installed pod but my ios folder remained empty:
iOS
For React Native >= 0.60.0 run the following command in the ios/ folder and skip the rest of the section.
pod install
CocoaPods
Add the following line to your Podfile:
pod 'BVLinearGradient', :path => '../node_modules/react-native-linear-gradient'
or:
This below is only for macOs ?
Manually
Open your project in Xcode, right click on Libraries and click Add Files to "Your Project Name" Look under node_modules/react-native-linear-gradient/ios and add BVLinearGradient.xcodeproj. (Screenshot 1) (Screenshot 2).
Add libBVLinearGradient.a to Build Phases -> Link Binary With Libraries (Screenshot 1) (Screenshot 2).
Click on BVLinearGradient.xcodeproj in Libraries and go the Build Settings tab. Double click the text to the right of Header Search Paths and verify that it has $(SRCROOT)/../react-native/React - if it isn't, then add it. This is so Xcode is able to find the headers that the BVLinearGradient source files are referring to by pointing to the header files installed within the react-native node_modules directory. (Screenshot).
How to do it in Windows and i don't have an ios map inside node_modules/react-native-linear-gradient/?
how can i make it work?
Thanks for your time
use this one if you are using expo
1 . paste this in terminal window :
expo install expo-linear-gradient
2.add the import statement to the file :
import {LinearGradient} from 'expo-linear-gradient';
worked for me !
Check whether these two lines are in your 'package file'.
'React', :path => '../node_modules/react-native'
'BVLinearGradient', :path =>
'../node_modules/react-native-linear-gradient'
If yes then --
Run "pod install" under $project path/ios before react-native run-ios.
Cheers!!
Easy Way..! Try This..!
Run this code in Terminal window
expo install expo-linear-gradient
Use this code to import the LinearGradient
import { LinearGradient } from "expo-linear-gradient";
I had similar issue with Android.
Solution: Kill the app and relaunch this should solve the problem
First, install the https://github.com/react-native-community/react-native-linear-gradient library.
then go to the cd ios and run
cd ios
pod install
now use go back using cd ..
and run (optional )
react-native link react-native-linear-gradient
now run
react-native run-ios
Simply you just need to go to ios folder
cd ios
pod install
That's it
If using expo and this error is thrown after installing react-native-linear-gradient follow along.
error ? the expo framework still does not have "sight" of the linear gradient package .
solution ? Run the command "expo install expo-linear-gradient" from your root folder, go to the file that you had previously imported the linear gradient as "import LinearGradient from 'react-native-linear-gradient" and change the line to "import {LinerGradient} from 'expo-linear-gradient'".
Restart your server, "expo start".
PS: This solution is only applicable for react-native projects being built using expo
if you're using windows & react-native cli (not expo):
1- in android/settings.gradle, check if
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
exist .. if not, add them
2- in android/app/build.gradle, check if
implementation project(':react-native-linear-gradient')
exists in dependecies{ ... } .. if not, add it
3- in android/app/src/main/java/com/{YOUR_APP_NAME}/MainApplication.java , find
#Override
protected List getPackages() { ....}
Then replace the comment // packages.add(new MyReactNativePackage());
with =>
packages.add(new LinearGradientPackage());
Android
If you are on android, simply do the native rebuild again with:
yarn android
or
npm run android

How to fix React Native Navigation with Expo - Module 'react-native-gesture-handler' does not exist in Haste module map

I am trying to add react-navigation to my Expo react-native application. I already made a mistake by installing react-native-gesture-handler, as it was included in the Expo library. I tried to fix this by removing the gesture handler in my package.json file and deleting the node modules and the package.lock file then running npm install again. This solution fixed a test project with a similar issue, however, this one still persists.
Here is my only react-native-gesture handler dependencies.
https://www.dropbox.com/s/j361xml8irsf8xg/Screen%20Shot%202019-04-11%20at%207.47.31%20PM.png?dl=0
And here is a link to what my react native screen is giving me
https://www.dropbox.com/s/v9xjzjliwhjwbft/IMG_AFC01F6D20DA-1.jpg?dl=0
Module 'react-native-gesture-handler' does not exist in the haste module map? Any idea how to fix this issue would be appreciated greatly.
You should delete your node_modules and package-lock.json or yarn.lock and run npm install or yarn again. After that run expo start -c to clear the cache for the packager and your problem will be resolved, most likely.