title: Conditional imports in React Native
body: <p>I'm having a bit of trouble getting conditional imports working in react native.</p>
  
  <p>I have some files that are used in a react web app and in react native. </p>
  
  <p>What I'd like:</p>
  
  <pre><code>if(process.env.REACT_PLATFORM === 'WEB') {
      import('some_file').then(({someFunc})=&gt; someFunc())
  }
  </code></pre>
  
  <p>Because 'some_file' imports <code>react_router</code>.</p>
  
  <p>However, this import is still happening, and the RN metro bundler throws</p>
  
  <p><code>UnableToResolveError: Unable to resolve module 'react-router' from 'some_file'.</code></p>
  
  <p>Even If I replace it as:</p>
  
  <pre><code>if(false) {
      import('some_file').then(({someFunc})=&gt; someFunc())
  }
  </code></pre>
  
  <p>It still trys to load <code>some_file</code>. Is there anyway to only import/require this file if a condition is met?</p>
  
  <p>Cheers!</p>
  
  <p>EDIT: 
  Things I've tried:</p>
  
  <ul>
  <li>Require instead of import.</li>
  <li><a href="https://babeljs.io/docs/plugins/syntax-dynamic-import/" rel="noreferrer">https://babeljs.io/docs/plugins/syntax-dynamic-import/</a></li>
  </ul>