title: Import ES Modules from CommonJS dynamically
body: <p>Is it possible to import ES Modules from CommonJS dynamically without having to change the file extension to mjs and if possible using old Node versions (older than V13)? I'm creating a CLI library which will dynamically import files from users project to auto-generate some code based on those files.</p>
  <pre class="lang-js prettyprint-override"><code>// bin.ts
  // This file will be transpiled to CommonJS
  const loadResourceFile = async (url: string) =&gt; {
    const resource = await import(url);
    return resource.default;
  }
  ...
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// rollup.config.js
  import typescript from 'rollup-plugin-typescript2';
  import pkg from './package.json';
  
  const commonOutputOptions = {
    banner: '#!/usr/bin/env node',
    preferConst: true,
    sourcemap: true,
  };
  
  export default {
    input: 'src/bin.ts',
    output: [
      {
        ...commonOutputOptions,
        file: pkg.main,
        format: 'cjs',
      },
      {
        ...commonOutputOptions,
        file: pkg.module,
        format: 'esm',
      },
    ],
    external: [...Object.keys(pkg.dependencies || {})],
    plugins: [typescript()],
    inlineDynamicImports: true,
  };
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// resource.js
  // This file will be a ES module
  import a from './a';
  
  export default {
     a,
     b: 'y',
  }
  </code></pre>
  <p>Thank you in advance!</p>