title: Dynamically load React component library from URL?
body: <p>I am working on documentation tool for Typescript library. The idea is to leverage parcel's watch mode to continuously build the library, and use the same in a pre-built documentation app.</p>
  <p>For the same I need to load a module library (built in another project) dynamically via URL.</p>
  <pre class="lang-js prettyprint-override"><code>&lt;script type=&quot;module&quot;&gt;
      const libraryModule = &quot;http://localhost:8080/lib.module.js&quot;;
      const promise = import(libraryModule);
  
      promise.then(library =&gt; {
          // do something with library
          window.ComponentLibrary = library;
      });
  &lt;/script&gt;
  </code></pre>
  <p>However, parcel replaces the above <code>import</code> with <code>require</code> and the load fails. Using <code>System.import</code> throws <code>System is not defined error</code>.</p>
  <p>I tried to use <code>dynamic-import-polyfill</code> and then initialize it as under and the use as below:</p>
  <pre class="lang-js prettyprint-override"><code>dynamicImportPolyfill.initialize({
      modulePath: 'http://localhost:13090', // Defaults to '.'
      importFunctionName: '$$import' // Defaults to '__import__'
  
      const promise = $$import(libPath);
  });
  </code></pre>
  <p>This throws the following error:</p>
  <pre><code>TypeError: Failed to resolve module specifier &quot;react/jsx-dev-runtime&quot;. Relative references must start with either &quot;/&quot;, &quot;./&quot;, or &quot;../&quot;
  </code></pre>
  <p>I have also tried using <code>script</code> type as <code>text/javascript</code> but doesn't work either.</p>
  <p>Looking for guidance on the best way here to get the component library loaded?</p>