I want to create a React Native module that can be installed using
npm install --save react-native-my-module
react-native link
cd ios && pod install
Using React Native 0.61.2 and a few required SDKs
Followed the instructions here to create a basic React Native module.
Installed the module using
npm install --s 'path to my-module'
- Ran
react-native link
- Installed the pod with
cd ios && pod install
I saw my pod being successfully installed.
The default native module skeleton sets up a method called sampleMethod that I invoke using
var myModule = NativeModules.MyModule;
console.log(myModule.sampleMethod());
But I get the following error message
TypeError: Cannot read property 'sampleMethod' of undefined
To fix the error I have to manually link the module with react-native link my-module
but then React Native complains
error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:
- react-native-my-module (to unlink run: "react-native unlink react-native-my-module")
What am I missing here? Do I have to manually link the module or is there a configuration file I can edit somewhere to avoid that?