54

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:

var PushNotification = require('react-native-push-notification');

Screenshot

4
  • 1
    i think u should try to use import instead of require Commented Aug 1, 2016 at 12:42
  • 2
    For example, I am using the "import" syntax, and I get the same error message. Commented Aug 1, 2016 at 16:46
  • I'm getting the same error but in Index.js:18:55 any solution? Commented Aug 26, 2019 at 20:32
  • 1
    Would be nice if they could tell us 'which modules'. Man I hate RN. Commented Apr 19, 2020 at 11:12

11 Answers 11

31

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.

enter image description here

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

Sign up to request clarification or add additional context in comments.

1 Comment

or you may follow this link for complete linking libraries in RN, facebook.github.io/react-native/docs/linking-libraries-ios.html
14

Sometime, if you had another react-native packager already running for a different app. You may see this problem.

Especially if the react-native versions are same and the previously started app requires a native module which is not available in the current app.

In these cases, you can kill the react packager terminal and restart it and problem should go away.

Also if it is the same app and you just upgraded. Make sure that it is linked properly. If not call react-native link again.

Comments

11

In my case, running a $ pod install inside /ios directory did the trick!

3 Comments

If you are using React Native 0.60 and higher, this should solve your issue.
I think most people forget to install the pods and run into this issue. Upvoted.
been a long since this was posted but figured I would ask, how do you do this when you are using expo?
4

remove react-native-push-notification in node_modules

run npm install [email protected]

Comments

3

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.

Comments

3

My issue had the same symptoms but a much different root cause. I had two React Native projects open in two different instances of Xcode. My Metro bundler was still running from Project A and causing problems running Project B in the simulator.

The fix: close the old terminal window spawned by Xcode that had the Metro Bundler running and re-run the project.

1 Comment

Very nice catch. Similar to a situation I just ran into: switched to new branch with a library swap, rebuilt the app, but didn't realize metro bundler was still running from before.
3
  1. npm i @react-native-community/push-notification-ios
  2. cd ios && pod install
  3. react-native unlink @react-native-community/push-notification-ios

That's how I solved it after struggling for hours.

1 Comment

God bless you 😁
1

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

1 Comment

Why? Is the other not being maintained? What about Android?
1

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.

Comments

0

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

Comments

0

Try command

$pod install 

in YourProject/ios. It worked for me.

Hope it helps?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.