title: ES6 how to import module "onto" another module
body: <p>I have already imported a <code>mapboxgl</code> module, then I am trying to import the second "submodule" geocoder like <code>import 'mapbox-gl-geocoder';</code> and like <code>import mapboxgl.Geocoder from 'mapbox-gl-geocoder';</code>, but that is obviously wrong approach, since I am only getting the error <code>Uncaught ReferenceError: mapboxgl is not defined</code>. How to do this right? Details below...</p>
  
  <p>I am trying to use the <a href="https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder/" rel="nofollow">Mapbox geocoding example</a> with ES6 (and webpack).</p>
  
  <p>The example uses 2 mapbox js libraries like this (skipping non-interesting part of the file):</p>
  
  <pre><code>&lt;script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.16.0/mapbox-gl.js'&gt;&lt;/script&gt;
  &lt;script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v1.0.0/mapbox-gl-geocoder.js'&gt;&lt;/script&gt;
  ...
  &lt;script&gt;
     ...
     var map = new mapboxgl.Map({
        ...
     });
  
     map.addControl(new mapboxgl.Geocoder());
     ...
  &lt;/script&gt;
  ...
  </code></pre>
  
  <p>So then I want to "translate" this to my project that uses ES6 (and webpack).</p>
  
  <p>When I only use the main mapbox-script (mapbox-gl), I can use that nicely like this:</p>
  
  <pre><code>import mapboxgl from 'mapbox-gl';
  let map = new mapboxgl.Map({
      ...
  });
  </code></pre>
  
  <p>But I am getting trouble when I try to include the "submodule" mapbox-gl-geocoder like this (I most probably import the second script the wrong way):</p>
  
  <pre><code>import mapboxgl from 'mapbox-gl';
  import 'mapbox-gl-geocoder';
  let map = new mapboxgl.Map({
      ...
  });
  map.addControl(new mapboxgl.Geocoder());
  </code></pre>
  
  <p>How can I "add" the submodule to the main module? When I try this, I only get the following error:</p>
  
  <blockquote>
    <p>Uncaught ReferenceError: mapboxgl is not defined</p>
  </blockquote>
  
  <p>Since it works nicely before I added the two lines <code>'import 'mapbox-gl-geocoder';</code> and <code>map.addControl(new mapboxgl.Geocoder());</code> I am guessing that I am importing incorrectly the second library.</p>