title: How to prevent typescript from transpiling dynamic imports into require()?
body: <p>I'm building a <code>discord.js</code> Discord bot. Now for some reason, <code>discord.js</code> doesn't work with <code>ESM</code> modules (a totally separate issue), so my bot app uses <code>CommonJS</code> modules. Now I have another project on my system called <code>Lib</code>, which has a lot of utility functions that I plan to use in several different projects so I don't have to rewrite them. This <code>Lib</code> project uses <code>ESM</code> modules. Since I have to import <code>Lib</code> from <code>DiscordBot</code>, I use the dynamic import syntax in typescript. Now, whenever I transpile my <code>DiscordBot</code> project, the dynamic imports get converted into <em>some ugly javascript module code</em>, and that ugly module code ultimately ends up using require(). Since require() can't import ESM modules, my bot ends up crashing.</p>
  <p>I tried however to stop my ts compiler, copy the code from my ts file that imports <code>Lib</code> then pasting that code into the corresponding JS file manually (and removing TS-exclusive features like type annotations and interfaces). Then I ran my bot app, and it worked perfectly fine. But I don't want to have to do this every time. So it's <code>tsc</code>'s compiling that's the problem. How do I fix this?</p>