title: esbuild + knex: Cannot find module '../../dialects/mysql/index.js'
body: <p>I'm currently trying to migrate some code from javascript to typescript. This code uses the <a href="https://www.npmjs.com/package/knex" rel="nofollow noreferrer">knex</a> package. I am able to build and run it using <code>tsc</code>, but i would like to use <code>esbuild</code> instead (for faster build).</p>
  <p>I build with:</p>
  <pre class="lang-sh prettyprint-override"><code>npx esbuild index.ts --bundle --platform=node --sourcemap=external --outfile=dist/index.js
  </code></pre>
  <p>But when i try to run the compiled code, i get:</p>
  <pre><code>Cannot find module '../../dialects/mysql/index.js'
  </code></pre>
  <p>I have no idea what is this <code>dialect</code> directory, and couldn't find any documentatio about it. I took a look at <a href="https://stackoverflow.com/questions/37323425/mysql-dialect-cannot-be-fount-in-knex-browserified">this SO question</a>, but couldn't really understand the code in it, and the error seemed to be more about <code>browserified</code>.</p>
  <p>Here is the code I used to reproduce the error:</p>
  <pre class="lang-js prettyprint-override"><code>import Knex from 'knex';
  
  const knex = Knex({
    client: 'mysql',
    connection: {
      port: 3306,
      host: 'localhost',
      database: 'database',
      user: 'user',
      password: 'password',
      charset: 'utf8mb4',
    },
  });
  
  const fetchData = async () =&gt; {
    const data = await knex('table')
      .select()
      .first();
    return data;
  };
  
  (async () =&gt; {
    const results = await fetchData();
    console.log(results);
  })();
  </code></pre>
  <p>Interesting thing is that by using only the <code>mysql</code> package without <code>knex</code> worked great with both <code>tsc</code> and <code>esbuild</code>.</p>
  <p>For some reason only the build from <code>esbuild</code> fails. I first thought i missed a package, and i installed <a href="https://www.npmjs.com/package/@types/node" rel="nofollow noreferrer">@types/node</a> and <a href="https://www.npmjs.com/package/@types/mysql" rel="nofollow noreferrer">@types/mysql</a> but it didn't solved my problem.</p>
  <p>If it helps, i use the following <code>tsconfig.json</code>:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;compilerOptions&quot;: {
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;outDir&quot;: &quot;dist&quot;,
      &quot;target&quot;: &quot;es6&quot;,
      &quot;esModuleInterop&quot;: true
    }
  }
  </code></pre>