Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

"Native module cannot be null"  #160

Closed

Description

@hedegren

I just upgrade React-native from 0.28 to 0.30, and get this error:
"Native module cannot be null"

I tried reinstall npm and remove all build files.

What can I do?

Activity

  1. tomazahlin commented on Aug 1, 2016

    @tomazahlin

    I have the same problem today on iOS.

    I think this has nothing to do with this repository, might be better to submit this issue / ask for help in react-native repository.

    On the other hand, if this repository is using "require" instead of "import", the issue might be here. I did not manage to solve this problem today.

  2. fmnxl commented on Aug 2, 2016

    @fmnxl
  3. tomazahlin commented on Aug 2, 2016

    @tomazahlin

    For example, I had it linked, but I still got this error. Today my coworker updated react-native to 0.31-rc. He said it solved the issue, but I haven't tried myself yet.

  4. charlesLin commented on Aug 10, 2016

    @charlesLin

    I run it on real iPad device successfully, but got the same error on iOS emulator.

    info:
    react-native 0.31.0

  5. zo-chu commented on Aug 14, 2016

    @zo-chu

    Any solutions on that? i have this error on emulator and on iphone it stopped loading the bundle ( might smth else cause this issue with bundle but it happened at the same time = ))
    react-native 0.31.0

  6. bkhanal commented on Sep 5, 2016

    @bkhanal

    I am getting the same error, has this been fixed. I am on RN 0.32

  7. npomfret commented on Sep 15, 2016

    @npomfret
    Contributor

    Have you checked in your MainApplicaiton that its been linked correctly? I think this is a common cause of this issue

  8. CharlieIGG commented on Sep 20, 2016

    @CharlieIGG

    Same issue on RN 0.32, in iOS, please if anyone has been able to fix this let us know.
    BTW – It all works fine on Android, the problem is only in iOS for me... I have linked libraries as per the official PushNotificationIOS docs. Any clues @charlesLin @tomazahlin @hedegren ??

  9. thbwd commented on Sep 26, 2016

    @thbwd

    Rebuilding and running the app from Xcode did the trick for me.

  10. littlemaneuver commented on Oct 8, 2016

    @littlemaneuver

    You do really need to go through manual procedure to get it work https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking if you don't have a developer account in apple center

  11. npomfret commented on Oct 10, 2016

    @npomfret
    Contributor

    No, just follow the instructions in the readme.

  12. tanapaydin commented on Feb 10, 2017

    @tanapaydin

    screen shot 2017-02-13 at 14 24 55
    I'm having the same issue. My versions are as follows:

    • "react-native": "0.39.2",
    • "react-native-push-notification": "^2.2.1"
      I've removed /node_modules /android /ios folders. Then ran the following commands in that order:
    • npm install
    • react-native upgrade
    • react-native link
      It seems the culprit is the required/import problem.
      If you change the following line from:
    • const NativeEventEmitter = require('NativeEventEmitter');
      to this:
    • import NativeEventEmitter from 'NativeEventEmitter';
      That did the trick. However, I shouldn't be changing the node_modules files. This should be fixed.
  13. liftyourgame commented on Apr 16, 2017

    @liftyourgame

    Where do you change the require to import? What file(s)?

  14. quantuminformation commented on Apr 27, 2017

    @quantuminformation

    Just done a fresh RN latest install and get the same error.

  15. 17 remaining items

  16. brenwell commented on Mar 28, 2019

    @brenwell

    Just a note for anyone as dumb as me. I have multiple RN projects and I had this problem because I had metro running for the wrong project

  17. cumen commented on Aug 5, 2019

    @cumen

    remove react-native-push-notification in node_modules

    run npm install react-native-push-notification@3.1.3

  18. ziaulrehman40 commented on Aug 8, 2019

    @ziaulrehman40

    Thanks @cumen This happened to me after an upgrade from 3.1.3 to 3.1.8. Strange thing is changelog is not yet there in https://github.com/zo0r/react-native-push-notification/blob/master/CHANGELOG.md

  19. GabeConsalter commented on Aug 8, 2019

    @GabeConsalter
    Contributor

    To solve RN 0.60:

    • add pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS' to ios/Podfile
    • execute pod install
    • execute react-native run-ios

    After added React-RCTPushNotification to my ios/Podfile, I'm having a duplication problem when building:

    duplicate symbol _RCTRemoteNotificationReceived in:
    .../Xcode/DerivedData/my-project-xcode-folder/Build/Products/Debug-iphoneos/RNCPushNotificationIOS/libRNCPushNotificationIOS.a(RNCPushNotificationIOS.o)
    .../Xcode/DerivedData/my-project-xcode-folder/Build/Products/Debug-iphoneos/React-RCTPushNotification/libReact-RCTPushNotification.a(RCTPushNotificationManager.o)
    ld: 1 duplicate symbol for architecture amd64
    
  20. thijs-qv commented on Aug 15, 2019

    @thijs-qv

    I also had the duplication error when adding React-RCTPushNotification in Podfile, so I didn't add it.
    Don't forget to update the import of the PushNotificationIOS module. This ended up solving the problem for me. PushNotificationIOS has been taken out of react-native core.

    Change
    import { PushNotificationIOS } from "react-native";
    to
    import PushNotificationIOS from "@react-native-community/push-notification-ios";

  21. Ovsdrak commented on Aug 15, 2019

    @Ovsdrak

    Solution FOUND!

    Platform: iOS
    Problem: Native module cannot be null
    Error line: var PushNotification = require('react-native-push-notification');

    SOLUTION

    NOTES:
    Do NOT use this docs:
    https://facebook.github.io/react-native/docs/pushnotificationios

    USE this ones:
    https://github.com/zo0r/react-native-push-notification
    https://github.com/react-native-community/react-native-push-notification-ios

    Package.json

    In your package.json consider this (ignore react native version):

    "react-native": "0.59.9"
    "react-native-push-notification": "^3.1.8",
    "@react-native-community/push-notification-ios": "^1.0.2",

    Run command: npm install

    Podfile

    Add this pod to your Podfile

    pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios'

    Run command in ios directory:
    pod install

    NOTES:
    Remove this subspec in your Podfile:
    'RCTPushNotification'

    Xcode Project

    PART 1:
    Add
    node_modules/@react-native-community/push-notification-ios/ios/PushNotificationIOS.xcodeproj

    To Directory
    yourProject/Libraries/

    Add
    libRNCPushNotificationIOS.a
    To
    NameProject -> Targets -> NameProject -> Build Phases -> Link Binary With Libraries

    Screenshot*
    Captura de Pantalla 2019-08-15 a la(s) 13 03 02

    PART 2: The reason of this part, is that the import done in AppDelegate.m works fine.

    Drag And Drop this folder
    yourProject/ios/Pods/Headers/Public/RNCPushNotificationIOS
    To
    Build Settings -> Search Paths -> Header Search Paths

    Set non-recursive property

    Screenshot
    Captura de Pantalla 2019-08-15 a la(s) 13 06 27

    NOTES:
    Remove RCTPushNotification.xcodeproj from yourProject/Libraries
    Make sure libRTCPushNotification.a disappeared from NameProject -> Targets -> NameProject -> Build Phases -> Link Binary With Libraries

    AppDelegate.m

    Add this import to your AppDelegate.m file:

    #import "RNCPushNotificationIOS.h"

    Add this in the @implementation section.

    ...
    // Required to register for notifications
    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
    {
      [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
    }
    // Required for the register event.
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
      [RNCPushNotificationIOS 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
    {
      [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
    }
    // Required for the registrationError event.
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
      [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
    }
    // Required for the localNotification event.
    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
      [RNCPushNotificationIOS didReceiveLocalNotification:notification];
    }
    

    NOTES:

    Remove

    • #import <React/RCTPushNotificationManager.h>
    • Every method using the RCTPushNotificationManager library, make sure you have only the above ones.
  22. sushrutha commented on Aug 19, 2019

    @sushrutha

    @Ovsdrak This solution works! Thank you!

  23. omererbil commented on Aug 25, 2019

    @omererbil

    USE those libraries:
    https://github.com/zo0r/react-native-push-notification
    https://github.com/react-native-community/react-native-push-notification-ios

    follow step by step,
    everything will work
    no need anything else
    not foget to pod install

  24. kazuooooo commented on Oct 29, 2019

    @kazuooooo

    @Ovsdrak kind answer perfect for me! thanks!

  25. kazuooooo commented on Nov 5, 2019

    @kazuooooo

    This error also occured old import way.

    import { PushNotificationIOS } from 'react-native

    need to fix to this

    import PushNotificationIOS from '@react-native-community/push-notification-ios'
  26. fkotsian commented on Nov 26, 2019

    @fkotsian

    Was able to figure this out thanks to the above 3 answers and everyone else on this thread 😄 .

    If you're on RN ^0.59 and rn-push-notifications ^3.1.9:

    react-native link @react-native-community/push-notification-ios
    

    The 'missing native module' is the linked @community library. RPN 3.1.3 -> 3.1.9 updated to use the community library over the native one, but that step is missing from the Getting Started docs

    🎉 😄 👍

  27. eramudeep commented on Dec 30, 2019

    @eramudeep

    Solution FOUND!

    Platform: iOS
    Problem: Native module cannot be null
    Error line: var PushNotification = require('react-native-push-notification');

    SOLUTION

    NOTES:
    Do NOT use this docs:
    https://facebook.github.io/react-native/docs/pushnotificationios

    USE this ones:
    https://github.com/zo0r/react-native-push-notification
    https://github.com/react-native-community/react-native-push-notification-ios

    Package.json

    In your package.json consider this (ignore react native version):

    "react-native": "0.59.9"
    "react-native-push-notification": "^3.1.8",
    "@react-native-community/push-notification-ios": "^1.0.2",

    Run command: npm install

    Podfile

    Add this pod to your Podfile

    pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios'

    Run command in ios directory:
    pod install

    NOTES:
    Remove this subspec in your Podfile:
    'RCTPushNotification'

    Xcode Project

    PART 1:
    Add
    node_modules/@react-native-community/push-notification-ios/ios/PushNotificationIOS.xcodeproj

    To Directory
    yourProject/Libraries/

    Add
    libRNCPushNotificationIOS.a
    To
    NameProject -> Targets -> NameProject -> Build Phases -> Link Binary With Libraries

    Screenshot*
    Captura de Pantalla 2019-08-15 a la(s) 13 03 02

    PART 2: The reason of this part, is that the import done in AppDelegate.m works fine.

    Drag And Drop this folder
    yourProject/ios/Pods/Headers/Public/RNCPushNotificationIOS
    To
    Build Settings -> Search Paths -> Header Search Paths

    Set non-recursive property

    Screenshot
    Captura de Pantalla 2019-08-15 a la(s) 13 06 27

    NOTES:
    Remove RCTPushNotification.xcodeproj from yourProject/Libraries
    Make sure libRTCPushNotification.a disappeared from NameProject -> Targets -> NameProject -> Build Phases -> Link Binary With Libraries

    AppDelegate.m

    Add this import to your AppDelegate.m file:

    #import "RNCPushNotificationIOS.h"

    Add this in the @implementation section.

    ...
    // Required to register for notifications
    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
    {
      [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
    }
    // Required for the register event.
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
      [RNCPushNotificationIOS 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
    {
      [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
    }
    // Required for the registrationError event.
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
      [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
    }
    // Required for the localNotification event.
    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
      [RNCPushNotificationIOS didReceiveLocalNotification:notification];
    }
    

    NOTES:

    Remove

    * `#import <React/RCTPushNotificationManager.h>`
    
    * Every method using the RCTPushNotificationManager library, make sure you have only the above ones.
    

    Great Worked for me
    Thank you

  28. ErtugrulBEKTIK commented on Jan 21, 2020

    @ErtugrulBEKTIK

    @Ovsdrak I cannot Drag And Drop RNCPushNotificationIOS folder to Header Search Paths because there is no folder in yourProject/ios/Pods/Headers/Public/ folder (I did pod install).

    So I get error on build as 'React/RCTEventEmitter.h' file not found in RNCPushNotificationIOS.h

    Any ideas?

  29. lukewlms commented on Aug 27, 2020

    @lukewlms

    Mocked the whole react-native-push-notification library and that seems to work well.

    jest.mock('react-native-push-notification', () => {
        return {
            addEventListener: jest.fn(),
            removeEventListener: jest.fn(),
            requestPermissions: jest.fn(),
            configure: jest.fn()
        }
    });

    Source: jestjs/jest#2208 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions