title: Import CommonJS default exports as named exports / Cannot load ES module
body: <p>I'm making a bot with discord.js using TypeScript,  but I get the following error when trying to run the resulting JavaScript.</p>
  <pre><code>import { Client, FriendlyError, SQLiteProvider } from 'discord.js-commando';
                   ^^^^^^^^^^^^^
  SyntaxError: Named export 'FriendlyError' not found. The requested module 'discord.js-commando' is a CommonJS module, which may not support all module.exports as named exports.
  CommonJS modules can always be imported via the default export, for example using:
  
  import pkg from 'discord.js-commando';
  const { Client, FriendlyError, SQLiteProvider } = pkg;
  </code></pre>
  <p>After doing those modifications, I get this error:</p>
  <pre><code>internal/process/esm_loader.js:74
      internalBinding('errors').triggerUncaughtException(
                                ^
  
  Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Eliqn\projects\He2\dist\commands\general\information.js
  require() of ES modules is not supported.
  require() of C:\Users\Eliqn\projects\He2\dist\commands\general\information.js from C:\Users\Eliqn\projects\He2\node_modules\require-all\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 information.js to end in .cjs, change the requiring code to use import(), or remove &quot;type&quot;: &quot;module&quot; from C:\Users\Eliqn\projects\He2\package.json.
  </code></pre>
  <p><code>information.js</code>:</p>
  <pre><code>export default class Information extends Command {
      /* ... */
  }
  </code></pre>
  <p><code>information.js</code> is being imported with <code>.registerCommandsIn(join(dirname(fileURLToPath(import.meta.url)), 'commands'));</code>. So I tried both solutions: if I remove the <code>&quot;type&quot;: &quot;module&quot;</code> as the message suggests, I get <code>SyntaxError: Cannot use import statement outside a module</code>, and if I change the extension to <code>.cjs</code>, it finally loads the file, but I don't understand why is this necessary and don't know how to output specific files as <code>.cjs</code> instead of <code>.js</code>. And despite that, the command is still not registered correctly.</p>
  <p>If useful, this is my <code>tsconfig.json</code>:</p>
  <pre><code>{
      &quot;compilerOptions&quot;: {
          &quot;allowJs&quot;: true,
          &quot;allowSyntheticDefaultImports&quot;: true,
          &quot;esModuleInterop&quot;: true,
          &quot;module&quot;: &quot;ES2020&quot;,
          &quot;moduleResolution&quot;: &quot;Node&quot;,
          &quot;noImplicitAny&quot;: true,
          &quot;noImplicitThis&quot;: true,
          &quot;strictNullChecks&quot;: true,
          &quot;outDir&quot;: &quot;dist&quot;,
          &quot;target&quot;: &quot;ES2020&quot;
      }
  }
  </code></pre>
  <p>I think there should be a more straightforward way to do this, but I find modules very confusing.</p>