ios icon indicating copy to clipboard operation
ios copied to clipboard

Invariant Violation: Native module cannot be null

Open hopewise opened this issue 4 years ago • 66 comments

At iOS, it builds successfully, however, when the app starts, I get this error:


Invariant Violation: Native module cannot be null.

constructor
    NativeEventEmitter.js:36:6
<global>
    PushNotificationIOS.js:17:32
loadModuleImplementation
    require.js:321:4
guardedLoadModule
    require.js:210:11
metroRequire
    require.js:128:6
module.exports.get__PushNotificationIOS
    react-native-implementation.js:257:11
<global>
    index.ios.js:10:13
loadModuleImplementation
    require.js:321:4
guardedLoadModule
    require.js:210:11


Any idea?

hopewise avatar Nov 03 '19 14:11 hopewise

this has been solved, but now I got this issue: https://github.com/react-native-community/react-native-push-notification-ios/issues/44

hopewise avatar Nov 04 '19 15:11 hopewise

How did you fix this?

rjshoemaker55 avatar Nov 04 '19 18:11 rjshoemaker55

I was using version v3.1.2 of react-native-push-notification which depends on outdated PushNotificationIOS, installing react-native-push-notification from main stream fixed my issue.

react-native-push-notification needs to create a new release to have this important commit: https://github.com/zo0r/react-native-push-notification/commit/5b02761d927cdacdc50fde41d58506f64d8154aa

hopewise avatar Nov 05 '19 10:11 hopewise

I am getting this same issue. not working even after installing from mainstream.

preetb123 avatar Nov 08 '19 10:11 preetb123

Sometimes, closing XCode and open in again then build would solve the issue.

hopewise avatar Nov 10 '19 07:11 hopewise

@hopewise can you please open this again? I am still experiencing this issue

"react": "16.9.0",
"react-native": "0.61.4",
"@react-native-community/push-notification-ios": "1.0.3",

Edit: we are using react-native-push-notification package. So not 100% sure the error lies in this package. But it seems that several people on RN version 61.4 are experiencing this error.

schumannd avatar Nov 14 '19 17:11 schumannd

@schumannd opened..

hopewise avatar Nov 18 '19 13:11 hopewise

Something is very simple. @react-native-community/push-notification-ios": "1.0.3" linked with Podfile after install and link commands. Just cd to ios/ and run 'pod install'. And restart the project.

radetsky avatar Nov 27 '19 21:11 radetsky

@radetsky that is exactly what I did and it resulted in this error message.

schumannd avatar Nov 28 '19 15:11 schumannd

+1 Same error here.

leonardomarciano avatar Nov 28 '19 19:11 leonardomarciano

+1 Same error here. React Native 0.61.5

Jmzp avatar Nov 29 '19 16:11 Jmzp

+1 Same error here. react-native 0.61.4

goodryanboy avatar Dec 02 '19 08:12 goodryanboy

+1 Same error here on react-native 0.61.5

asleepace avatar Dec 03 '19 01:12 asleepace

Same error here with RN 59.10. I have patched above zo0r/react-native-push-notification@5b02761 manually. All code/setup steps in RN/XCode completed as per https://facebook.github.io/react-native/docs/pushnotificationios but no luck. Any ideas?

manish-jain-1 avatar Dec 05 '19 16:12 manish-jain-1

Hi! I'm having the same issue. BUT I know what is the cause, it's the package react-navigation-stack or react-navigation-tabs. They both use the package react-native-reanimated which is creating the following error for me.

image

I have tried everything that all of you already posted before me. And none of them have worked successfully, unfortunately...

If anyone has any idea how to fix this issue. You would really help me out big time.

WoutVanneste avatar Dec 07 '19 15:12 WoutVanneste

So, here's the solution that worked for me for Xcode legacy build systems: remove react-native core IOS xcodeproj project from libraries, also, remove one that comes with react-native-push-notification (Push notification manager something) and add new XCodeProj file from this iOS project from below node_modules path. Also add path to Xcode > build settings > header search path > add $(SRCROOT)/../node_modules/@react-native-community/push-notification-ios/ios (non-recursive)

Path for XCodeproj - $(SRCROOT)/../node_modules/@react-native-community/push-notification-ios/ios

image

manish-jain-1 avatar Dec 12 '19 22:12 manish-jain-1

Hello, have you solved it?

chentianci123 avatar Dec 23 '19 02:12 chentianci123

+1 Same error here on react-native 0.61.5 Hello, have you solved it?

chentianci123 avatar Dec 23 '19 02:12 chentianci123

same error here 0.61.5

gagandeep-s avatar Dec 23 '19 11:12 gagandeep-s

I got the same issue as @Wout-Vanneste-student described. https://github.com/react-native-community/react-native-push-notification-ios/issues/43#issuecomment-562862506

This is how it worked for me; After I installed these libraries(described in the post in the link above) through yarn i had to do also pod install and it worked.

bettimms avatar Dec 24 '19 10:12 bettimms

Same problem here. 0.61.5

tomthornton avatar Dec 27 '19 17:12 tomthornton

The same problem also 0.61.5 react-native version

patrikmasiar avatar Jan 03 '20 12:01 patrikmasiar

Same issue on 0.61.5. Only happens on iOS, Android is fine. Can't figure out which package it is or how to debug this. Any suggestions?

rnnyrk avatar Jan 08 '20 11:01 rnnyrk

For those who are having trouble getting this module on 0.61.5, please run pod install in your ios folder.

Naturalclar avatar Jan 08 '20 14:01 Naturalclar

ok, my solution was: I had an old version 0.59 and now I have 0.61.5 I used react-native-push-notification for both platforms my solution was

  1. remove the package, yarn remove react-native-push-notification
  2. delete last code in xcode appdelegate.m
/*#import <React/RCTPushNotificationManager.h>*/ - //here

#import <UserNotifications/UserNotifications.h>

@implementation AppDelegate

 /*- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
 {
  [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
 }
 // Required for the register event.
 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
 {
  [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
 }
 // Required for the notification event. You must call the completion handler after handling the remote notification.
 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
                                                        fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
 {
   [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
 }
 // Required for the registrationError event.
 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
 {
  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
 }
 // Required for the localNotification event.
 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
 {
  [RCTPushNotificationManager didReceiveLocalNotification:notification];
 }*/ - //here

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"projectName"
                                            initialProperties:nil];
  1. install again, yarn add react-native-push-notification
  2. add in pod file this line pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios/RNCPushNotificationIOS.podspec'
  3. cd ios/ && pod install clear package and build in xcode again it works for me ;)

inmaSecret avatar Jan 17 '20 14:01 inmaSecret

Same problem here. 0.59.8

ErtugrulBEKTIK avatar Jan 21 '20 21:01 ErtugrulBEKTIK

@inmaSecret is this code working for u in ios? For me notification is not showing, but working fine in android

nabeelItilite avatar Feb 08 '20 10:02 nabeelItilite

@inmaSecret is this code working for u in ios? For me notification is not showing, but working fine in android

the block code in xcode appdelegate.m related to pushNotification should be removed. my problem was that the appdelegate code left old RCTPushNotificationManager functionality after delete this I could fix the problem. Could you solve your problem with my solution finally?, it works for me in both

inmaSecret avatar Feb 10 '20 10:02 inmaSecret

@inmaSecret thanks, it worked for me. but still issue with getting messages while app in background in ios. I am sending data mesasges. any suggestion ?

nabeelItilite avatar Feb 11 '20 05:02 nabeelItilite

I am getting this issue as well. Unfortunately, none of the above solutions have worked for me.

Ryan113 avatar Feb 17 '20 23:02 Ryan113