title: Must use import to load ES Module
body: <p>I am trying to create a service to convert an SVG to a PNG using the <a href="https://www.npmjs.com/package/svg2img" rel="nofollow noreferrer">svg2img</a> package. I have it working locally using <code>vercel dev</code>, however when I try to deploy to vercel I always get this error:</p>
  <pre><code>2021-09-27T01:11:56.532Z    e3a35069-8a51-4e1d-81b9-110e1b17e2be    ERROR   Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/api/node_modules/canvg/lib/index.js
  require() of ES modules is not supported.
  require() of /var/task/api/node_modules/canvg/lib/index.js from /var/task/api/node_modules/svg2img/index.js is an ES module file as it is a .js file whose nearest parent package.json contains &quot;type&quot;: &quot;module&quot; which defines all .js files in that package scope as ES modules.
  Instead rename /var/task/api/node_modules/canvg/lib/index.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from /var/task/api/node_modules/canvg/package.json.
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1089:13)
      at Module.load (internal/modules/cjs/loader.js:937:32)
      at Function.Module._load (internal/modules/cjs/loader.js:778:12)
      at Module.require (internal/modules/cjs/loader.js:961:19)
      at require (internal/modules/cjs/helpers.js:92:18)
      at Object.&lt;anonymous&gt; (/var/task/api/node_modules/svg2img/index.js:1:13)
      at Module._compile (internal/modules/cjs/loader.js:1072:14)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
      at Module.load (internal/modules/cjs/loader.js:937:32)
      at Function.Module._load (internal/modules/cjs/loader.js:778:12) {
    code: 'ERR_REQUIRE_ESM'
  }
  RequestId: e3a35069-8a51-4e1d-81b9-110e1b17e2be Error: Runtime exited with error: exit status 1
  Runtime.ExitError
  </code></pre>
  <p>Here is what my code looks like:</p>
  <pre class="lang-js prettyprint-override"><code>import svg2img from 'svg2img';
  
  export default function(req, res) {
    const url = req.query.url;
    const width = req.query.width;
    const height = req.query.height;
    const size = Math.min(width, height);
    svg2img(url, {width: size, height: size, preserveAspectRatio: true},
      function(error, buffer) {
        if (buffer) {
          res.send(buffer);
        }
    });
  };
  </code></pre>
  <p>Here is the package.json</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;name&quot;: &quot;svg2png&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;convert svgs to pngs&quot;,
    &quot;scripts&quot;: {
      &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
    },
    &quot;author&quot;: &quot;me&quot;,
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;dependencies&quot;: {
      &quot;svg2img&quot;: &quot;^0.9.3&quot;
    },
    &quot;type&quot;: &quot;module&quot;
  }
  </code></pre>