title: Loading modules conditionally in react-native
body: <p>I'm working to make a library to work on both NodeJS and ReactNative. Some of the native NodeJS modules are not supported in ReactNative, so I tried to load them conditionally. This however doesn't work:</p>
  
  <pre><code>if (true) {
      require('a'); // module 'a' works in ReactNative
  } else {
      require('b'); // module 'b' doesn't work in ReactNative
  }
  </code></pre>
  
  <p>Unfortunately, BOTH require statements ad executed and loading of 'b' throws exception :(</p>
  
  <p>Now I have the following options:</p>
  
  <ol>
  <li>To create a new version of the library, specific for ReactNative, using only modules, which work there.</li>
  <li>I've heard you can specify "react-native" in package.json and this would help to resolve this issue. However, I can't find documentation anywhere, is it documented somewhere?</li>
  </ol>
  
  <p>How in general you would recommend to make my library to work in both Node and ReactNative?</p>
  
  <p>Thanks,</p>