'null is not an object react native error when I try to use native implementation from a module in react-native app

I'm creating a plugin/module that uses many modules with native implementations like @react-native-async-storage/async-storage, react-native-fs, @react-native-community/netinfo, react-native-audio-recorder-player any many others. Link to my plugin/module is this. When I run this code as a standalone app, it runs fine, but when I use this npm module then I get this error. In the host application, I installed all of the peer dependencies and linked them automatically and manually both, but the error is never resolved. So to summarize the situation, below are the points:

  • The npm module has the index.js with exporting the code only.
  • The code uses @react-native-async-storage/async-storage, react-native-fs, @react-native-community/netinfo, react-native-audio-recorder-player etc..
  • The npm module has all the dependencies as peerDependencies so the host app has them and links to the android files.
  • The host app links all these packages with react-native link command but error is still shown.
  • Host and guest, both have same react and react-native versions too: "react": "17.0.1", "react-native": "0.64.2"
  • I also tried having all these packages as dependencies of the module but in that case, I could not link them with this command because we need those packages in the host application.

Any kind of help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source