title: ESM changes are making conflict in my NestJS project
body: <p>I'm the author of <a href="https://github.com/vahidvdn/nestjs-cashify" rel="nofollow noreferrer">nestjs-cashify</a>. I decided to update my package as well as the underlying packages. I'm encountering some issues after updating one the core packages that I'm using it. Since my package ts configuration is set to <code>es6</code> not <code>es2020</code>. (In other words, the new version of package that I'm using is changed to <code>es2020</code> recently)</p>
  <p>When I want to use my package in a regular NestJS project (in my example folder), I get these errors:</p>
  <pre><code>/home/vahidnajafi/repos/nestjs-cashify/dist/cashify.module.js:21
  const cashify_1 = require(&quot;cashify&quot;);
                    ^
  
  Error [ERR_REQUIRE_ESM]: require() of ES Module /home/vahidnajafi/repos/nestjs-cashify/node_modules/cashify/dist/index.js from /home/vahidnajafi/repos/nestjs-cashify/dist/cashify.module.js not supported.
  Instead change the require of index.js in /home/vahidnajafi/repos/nestjs-cashify/dist/cashify.module.js to a dynamic import() which is available in all CommonJS modules.
      at Object.&lt;anonymous&gt; (/home/vahidnajafi/repos/nestjs-cashify/dist/cashify.module.js:21:19)
      at Object.&lt;anonymous&gt; (/home/vahidnajafi/repos/nestjs-cashify/dist/index.js:18:14)
      at Object.&lt;anonymous&gt; (/home/vahidnajafi/repos/nestjs-cashify/example/dist/app.module.js:12:26)
      at Object.&lt;anonymous&gt; (/home/vahidnajafi/repos/nestjs-cashify/example/dist/main.js:4:22) {
    code: 'ERR_REQUIRE_ESM'
  }
  </code></pre>
  <p>This makes sense since my project is set to &quot;es6&quot; and when I build, it uses &quot;require&quot; for ES module (core module is now ESM from new version): This is the error: <strong>require() of ES Module /index.js from /cashify.module.js not supported.</strong></p>
  <p>Then I decided to set my project to &quot;es2020&quot; as well. Now, this error is gone (since in my build result it's not using <code>require</code> anymore, it's using import statement).</p>
  <p>In my example folder (<strong>regular NestJS project</strong>), which I'm testing my package, this config is set: <code>&quot;target&quot;: &quot;es2017&quot;,</code></p>
  <p>Now I see the following error:</p>
  <pre><code>SyntaxError: Unexpected token 'export'
  </code></pre>
  <p><strong>IMPORTANT NOTE:</strong></p>
  <p>Even though that's not a good idea to change my example project's configuration (<strong>since all NestJS developers will have to do this</strong>), I tried to fix this anyway.  I changed it to <code>es2020</code> as well.</p>
  <p>This time, I get the following errors:</p>
  <pre><code>(node:89687) Warning: To load an ES module, set &quot;type&quot;: &quot;module&quot; in the package.json or use the .mjs extension.
  /home/vahidnajafi/repos/nestjs-cashify/example/dist/main.js:1
  import { NestFactory } from '@nestjs/core';
  ^^^^^^
  
  SyntaxError: Cannot use import statement outside a module
  </code></pre>
  <p>I also tried to set &quot;type&quot;: &quot;module&quot; in package.json file (as mentioned in the error message) and then I see this error:</p>
  <pre><code>internal/process/esm_loader.js:74
      internalBinding('errors').triggerUncaughtException(
                                ^
  
  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/vahidnajafi/repos/nestjs-cashify/example/dist/app.module' imported from /home/vahidnajafi/repos/nestjs-cashify/example/dist/main.js
  </code></pre>
  <p>Any idea?</p>