title: How to move to ESM
body: <p>I am using <a href="https://eggjs.org/" rel="nofollow noreferrer">Egg framework</a> for my NodeJs(v14.15.4) application</p>
  <p>I want to use latest version of <code>p-debounce</code> library, <a href="https://github.com/sindresorhus/p-debounce/releases/tag/v3.0.0" rel="nofollow noreferrer">the package is now pure ESM</a>, Instead of <code>const pDebounce = require('p-debounce')</code> I must use <code>import pDebounce from 'p-debounce'</code> that not works on EggJs</p>
  <h2>If I use import</h2>
  <pre class="lang-js prettyprint-override"><code>(node:10636) Warning: To load an ES module, set &quot;type&quot;: &quot;module&quot; in the package.json or use the .mjs extension.
  (Use `node --trace-warnings ...` to show where the warning was created)
  test.js:5
  import pDebounce from 'p-debounce'
  ^^^^^^
  
  SyntaxError: Cannot use import statement outside a module
  </code></pre>
  <h2>If I use require</h2>
  <pre><code>internal/modules/cjs/loader.js:1080
        throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
        ^
  
  Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: .\node_modules\p-debounce\index.js
  require() of ES modules is not supported.
  require() of .\node_modules\p-debounce\index.js from .\test.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 index.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from .\node_modules\p-debounce\package.json.
  
  </code></pre>
  <h2>If I add  &quot;type&quot;: &quot;module&quot; in the package.json</h2>
  <pre><code>const path = require('path');
               ^
  
  ReferenceError: require is not defined
  </code></pre>
  <p>I have many <code>require</code> in my application and not want to change all to import at the moment</p>
  <ol>
  <li>What is &quot;type&quot;: &quot;module&quot; in the package.json ?</li>
  <li>How can I fix the error?</li>
  </ol>