Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native, "Native module cannot be null"

Tags:

react-native

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

like image 402
BlackMouse Avatar asked Aug 01 '16 12:08

BlackMouse


4 Answers

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

like image 190
夜一林风 Avatar answered Nov 05 '22 21:11

夜一林风


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.

like image 14
Seraj Ahmad Avatar answered Nov 05 '22 23:11

Seraj Ahmad


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

like image 10
simaAttar Avatar answered Nov 05 '22 23:11

simaAttar


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.

like image 3
Shivam Sinha Avatar answered Nov 05 '22 21:11

Shivam Sinha