1

Can somebody explain how the module system in react navigation works? There are getters inside module.exports (with node.js-like require()), and also es6 style export default in other files. I completely stuck how to make sense of it. I tried to look into git history, but the initial git commit (first public release) already had this solution in place.

The main file (src/react-navigation.js):

module.exports = {
  get createKeyboardAwareNavigator() {
    return require('@react-navigation/native').createKeyboardAwareNavigator;
  },
};

react-navigation-native/src/createKeyboardAwareNavigator.js:

export default (Navigator, navigatorConfig) =>
  class KeyboardAwareNavigator extends React.Component {
};

So why 1. there is module.exports instead of export? 2. why there is a getter inside module.exports? 3. how can require and export default be mixed?

arcol
  • 1,510
  • 1
  • 15
  • 20
  • Possible duplicate of [Using Node.js require vs. ES6 import/export](https://stackoverflow.com/questions/31354559/using-node-js-require-vs-es6-import-export) – Randy Casburn Oct 14 '18 at 19:14
  • 1. because CommonJS give ability require file in inner scope `for each` for example. 2. So the `get` always require current `().createKeyboardAwareNavigator` when is requested. 3. Because the `import` - es6 and `module.exports` - commonJS are features of nodeJS. – Eduard Jacko Oct 15 '18 at 00:36

0 Answers0