React-native, “Native module cannot be null”

前端 未结 12 1108
星月不相逢
星月不相逢 2020-12-09 14:42

I just upgrade React-native from 0.28 to 0.30, and get this error:

\"Native module cannot be null\".

The problem seem to be with the line/package:

相关标签:
12条回答
  • 2020-12-09 15:03

    The red-box complaints react-native cannot find some symbol <unkown> in PushNotificationIOS.js line 18.

    This usually happens when you fail to link the third lib to your target causing NativeModules find nothing at attempt.

    To solve this, your Project Navigator -> Target -> General -> Linked Frameworks and Libraries, make sure somelib.a is there.

    In your case, please follow the ios install guides and react-native doc

    0 讨论(0)
  • 2020-12-09 15:07

    Please use react native community's ios push notification package instead of native's one.

    https://github.com/react-native-community/react-native-push-notification-ios

    Remove RCTPushNotification project from your libraries and try to use react-native-community's ios push notification. You need to follow the guide. (There are some differences in xcode and linking.)

    0 讨论(0)
  • 2020-12-09 15:11

    1- In iOS message is 'Native module cannot be null'

    2- In Android message is 'null is not an object evaluating RNFSManager etc'

    Meaning is the same and solutions are different, for both cases you need to link native library manually.

    Solution for iOS is run pod install in iOS Directory, then react-native run-ios to re-run the app.

    Solution for android is react-native link react-native-fs then react-native run-android to re-run the app.

    Note: In android better is to open project in android studio again to avoid any inconvenience.

    0 讨论(0)
  • 2020-12-09 15:12

    if it helps someone. Manual link the library in node_modules/react-native/libraries/PushNotificationIOS/RCTPushNotification.xcodeproj for ios https://facebook.github.io/react-native/docs/linking-libraries-ios#manual-linking

    that's where the manual linking refers to. not react-native-push-notification

    0 讨论(0)
  • 2020-12-09 15:16

    Try command

    $pod install 
    

    in YourProject/ios. It worked for me.

    Hope it helps?

    0 讨论(0)
  • 2020-12-09 15:19

    I think this has to do with how to export and import your modules. Make sure each corresponding

    If you export your module like this module.exports = moduleName; You should import using var moduleName = require('moduleName');

    If export your module using export default moduleName;. You should import using import ModuleName from './ModuleName;

    Review all your exports and imports.

    0 讨论(0)
提交回复
热议问题