2 thoughts on “Native module cannot be null ?

  1. This error is because you are developing using Expo.
    Expo managed workflow is completely incompatible with other native modules.
    Bare workflow can work, ejected can work.

Comments are closed.

4 thoughts on “Native module cannot be null?

  1. I’ve seen this error only when react-native-reanimated wasn’t linked or after linking I forgot to rerun the app (react-native run-ios). I can’t figure out what it was without a code.

  2. The issue is that react-native link react-native-reanimated is not properly linking the react-native-reanimated library. You have to link it manually in Xcode. i.e add RNReanimated.xcodeproj to the libraries folder, then add libReanimated.a to the link binary with libraries

  3. ℹ️ TIP:
    To verify if linking works properly or not, just check ios/ProjectName.xcodeproj/project.pbxproj should have few changes, including libRnReanimated.a.
    If changes are in place, make sure to have run pod install from ios folder.

Comments are closed.

20 thoughts on ““Native module cannot be null”

  1. 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.
  2. What I did to fix this was:

    1. Close all open react-native packagers
    2. Clean the build
    3. Run the app

    Simply running the app via the command line didn’t work for me.

  3. We use CocoaPods in our project and simple linking doesn’t work.
    react-native version: 0.54.3

    Here is a how-to for CocoaPods users:

    • Add PushNotification subspec to Podfile:
    pod 'React', :path => '../node_modules/react-native', :subspecs => [
        'Core',
        ...
        'RCTPushNotification',
        ...
      ]
    
    • Execute pod update Terminal when you in ios folder
    • Open *.xcworkspace workspace file in XCode (for our 0.54.3 react-native version the only working XCode version is 9.2)
    • Choose the first tab on the left pane
    • There are two top-most projects in your left pane now – Pods and your project, expand your project
    • Open Libraries folder
    • Open node_modules folder in Finder and find RCTPushNotification.xcodeproj file
    • Drag RCTPushNotification.xcodeproj file from Finder to Libraries folder in XCode
    • Choose your target on the right in Xcode -> General tab
    • Scroll to Linked Frameworks and Libraries
    • Tap on plus sign
    • Enter libRCTPushNotification in search input field (not tvOS)
    • If it’s found – add it to the project
    • Try to build you project via react-native run-ios and then run it

    I hope it will work for you, mates 🤗

  4. Alright this took me forever to figure out. Shoutout to @8of his solution worked great for me. I started with an expo app using create-react-native-app but had to detach to ExpoKit for reasons.

    @8of ‘s solution works great for detached expo applications. After adding

    pod 'React', :path => '../node_modules/react-native', :subspecs => [
        'Core',
        ...
        'RCTPushNotification',
        ...
      ]
    

    To my podfile, it worked flawlessly. I was able to follow the remaining steps from the FB docs here : https://facebook.github.io/react-native/docs/pushnotificationios.html#content

    Hope this helps someone! It took me way too long to figure it out.

  5. I had the same problem with create-react-native-app. I had to delete the import * as StatusBar from "react-native"; line to fix it.

  6. 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

  7. WRONG WAY (Old message to keep the history)

    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

    Check the next answers.

  8. remove react-native-push-notification in node_modules

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

  9. 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
    
  10. 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.
  11. 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'
  12. 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: facebook/jest#2208 (comment)

Comments are closed.

6 thoughts on “Native module cannot be null

  1. Yeah react-native link didn’t work for me either. I followed these instructions and my error went away.

        Add the following to your Project: node_modules/react-native/Libraries/PushNotificationIOS/RCTPushNotification.xcodeproj
        Add the following to Link Binary With Libraries: libRCTPushNotification.a
        Add the following to your Header Search Paths: $(SRCROOT)/../node_modules/react-native/Libraries/PushNotificationIOS and set the search to recursive
    

Comments are closed.

1 thought on “Native module cannot be null

Comments are closed.

Native module cannot be null

Platform => IOS
Xcode => v10. 3
React native => v0.60.4
react-native-push-notification => v^3.1.8

Please help. What is the problem?

I think plugin is not working properly with latest version rn 0.60.4

Im tried different solutions but not working.

pod file

pod ‘React-RCTPushNotification’, :path => ‘../node_modules/react-native/Libraries/PushNotificationIOS’

4 thoughts on “Native module cannot be null

  1. fixed this issue with the following using v3.1.8.

    Make sure you’ve already installed @react-native-community/push-notification-ios so it’s in your node_modules.

    added this line to Podfile
    pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios/RNCPushNotificationIOS.podspec'

    Then run inside your ios directory
    pod install

  2. @Developer-Nijat if you are using the latest version then import PushNotification from 'react-native-push-notification'; is now using the PushNotificationIOS from the community package, so you do not have to do the two imports, this package does it for you.

    You just have to unlink the react native core version and then link the community version and then you can still use import PushNotification from 'react-native-push-notification'; as before.

Comments are closed.

1 thought on “Native module cannot be null

Comments are closed.

1 thought on “Native module cannot be null

Comments are closed.

1 thought on “Native module cannot be null

Comments are closed.

4 thoughts on “Native module cannot be null?

  1. I’ve seen this error only when react-native-reanimated wasn’t linked or after linking I forgot to rerun the app (react-native run-ios). I can’t figure out what it was without a code.

  2. The issue is that react-native link react-native-reanimated is not properly linking the react-native-reanimated library. You have to link it manually in Xcode. i.e add RNReanimated.xcodeproj to the libraries folder, then add libReanimated.a to the link binary with libraries

  3. ℹ️ TIP:
    To verify if linking works properly or not, just check ios/ProjectName.xcodeproj/project.pbxproj should have few changes, including libRnReanimated.a.
    If changes are in place, make sure to have run pod install from ios folder.

Comments are closed.

1 thought on “Native module cannot be null

Comments are closed.