title: How can I call a JavaScript function that is a module with wasm-bindgen?
body: <p>I'm trying to use the Web3 JavaScript library from Rust and I'm stuck. The standard usage of the library starts with:</p>
  <pre class="lang-js prettyprint-override"><code>// In Node.js use: const Web3 = require('web3');
  
  let web3 = new Web3(Web3.givenProvider || &quot;ws://localhost:8545&quot;);
  </code></pre>
  <p>The module you're supposed to import is a constructor, that also has some other properties. My Rust code that's supposed to bind this API looks like this:</p>
  <pre class="lang-rust prettyprint-override"><code>#[wasm_bindgen(module = &quot;web3&quot;)]
  extern &quot;C&quot; {
      type Web3;
  
      #[wasm_bindgen(constructor)]
      fn new(_: &amp;Provider) -&gt; Web3;
  
      type Provider;
  
      static givenProvider: Provider;
  }
  </code></pre>
  <p>Which ends up outputting <code>import { Web3, givenProvider } from 'web3';</code> and trying to run <code>new Web3(...)</code> which fails. It should be doing something like <code>import * as Web3 from 'web3';</code>, running <code>new Web3(...)</code> and referencing <code>Web3.givenProvider</code>.</p>
  <p>How can I get wasm-bindgen to output code like that?</p>