frostney / react-native-create-library

:notebook: Command line tool to create a React Native library with a single command
MIT License
1.45k stars 113 forks source link

modules.export seems not to work #33

Closed pepavesely closed 6 years ago

pepavesely commented 7 years ago

Hi guys. I created a library that exports a bunch of components. The index.js looks like this:

import React from 'react';
import { NativeModules } from 'react-native';
import ClickInfoTask from './app/components/clickInfoTask';

const { RNEduLibrary } = NativeModules;

module.exports = RNEduLibrary;
module.exports.ClickInfoTask = ClickInfoTask;

I installed this using npm install and react-native link and everything works fine on Android. However, on iOS I got the following error: null is not an object (evaluating 'module.exports.clickInfoTask = _clickInfoTask2.default')

I logged the imported ClickInfoTask and it's not null.

The ClickInfoTask class: export default class ClickInfoTask extends Component { /* content of the class */ }

(the project is here: github.com/pepavesely/EduLibrary

I'd much appreciate any help.

Regards, Josef Vesely

pepavesely commented 7 years ago

I solved this issue by replacing module.exports.XYZ with export { XX, YY, ... }

maicki commented 6 years ago

Yep use either module.exports = {} or export {} in here makes more sense.

koolkarni commented 6 years ago

I have same issue https://stackoverflow.com/questions/51451329/react-native-not-calling-android-native-method-from-parent-app