react-native-create-library icon indicating copy to clipboard operation
react-native-create-library copied to clipboard

iOS module not importable after install

Open grisaitis opened this issue 5 years ago • 6 comments

I'm having an issue with importing modules created with this utility.

If I...

  1. create a library, and run npm install in the folder
  2. create a project somewhere else
  3. install the library /at/its/path with react-native install in my project
  4. and then import RNMyLibrary from 'react-native-my-library';

I see that the value for RNMyLibrary is null.

Am I doing something wrong?

Also, if I modify the Objective C code and add a method to the module, like in the docs example with the iOS calendar API, I get an error that null has no method. Something is weird with my import, and I'm not sure what.

grisaitis avatar May 28 '19 21:05 grisaitis

I made a repo where I demo this issue: https://github.com/grisaitis/issue-rn-native-module-import

grisaitis avatar May 28 '19 22:05 grisaitis

Can confirm, same issue happens even without importing any native library. If I try exporting a simple method and import it in another project, it is also undefined.

kitty7756 avatar Jun 06 '19 22:06 kitty7756

you need a podspec file in the root of your project. Here is an example - https://github.com/react-native-community/react-native-webview/blob/master/react-native-webview.podspec

firofame avatar Jun 21 '19 10:06 firofame

@grisaitis Did you ever make any progress with this? I've been having the exact same issue on iOS as the lib doesn't export any methods :/

dsyne avatar Jul 10 '19 13:07 dsyne

I just had to export a dummy function to get my new native module to work/importable

RCT_EXPORT_METHOD(getModuleList: (RCTResponseSenderBlock)callback)
{
   NSArray *nativeModuleList = @[@"react-native-fbsdk", @"react-native-camera", @"react-native-maps"];
   callback(@[nativeModuleList]);
}

// call function in js like so
import MyModule from "MyModule"
MyModule.getModuleList(list => console.log(list))

drewandre avatar Aug 29 '19 01:08 drewandre

@grisaitis I have the same issue, were you able to fix it and how?

EnasAhmedZaki avatar Feb 10 '21 07:02 EnasAhmedZaki