title: Can I use Knex.js with Next.js?
body: <p>I'm trying to use Knex.js with my Next.js application, since Knex.js is the only SQL query builder I know very well and feel most comfortable to develop with. However, I can't find a way to integrate Knex.js with my application. Here's the source code:</p>
  <pre class="lang-js prettyprint-override"><code>import knex from 'knex';
  
  const connection = knex({
    client: 'mysql',
    connection: process.env.DATABASE_URL,
    asyncStackTraces: true,
    debug: true
  });
  
  export default connection;
  </code></pre>
  <p>And whenever I try to use it in my index page, which looks like this:</p>
  <pre class="lang-js prettyprint-override"><code>import Head from 'next/head';
  import Container from 'react-bootstrap/Container';
  import Col from 'react-bootstrap/Col';
  import Row from 'react-bootstrap/Row';
  import Navbar from '../components/Navbar';
  import con from '../database/connection';
  
  export async function getServerSideProperties(context) {
    const result = await con('test').select();
    return {
      props: {
        test: result
      }
    }
  }
  
  export default function Home({ test }) {
    return (
      &lt;&gt;
        &lt;Head&gt;
          &lt;title&gt;Create Next App&lt;/title&gt;
          &lt;meta name=&quot;description&quot; content=&quot;Generated by create next app&quot; /&gt;
          &lt;link rel=&quot;icon&quot; href=&quot;/favicon.ico&quot; /&gt;
        &lt;/Head&gt;
        &lt;Navbar /&gt;
        &lt;Container className=&quot;text-center&quot;&gt;
          &lt;Row&gt;
            &lt;Col&gt;
              {test}
            &lt;/Col&gt;
          &lt;/Row&gt;
        &lt;/Container&gt;
      &lt;/&gt;
    )
  }
  </code></pre>
  <p>I receive this error:</p>
  <pre><code>error - ./node_modules/knex/lib/migrations/util/fs.js:1:0
  Module not found: Can't resolve 'fs'
  Did you mean './fs'?
  Requests that should resolve in the current directory need to start with './'.
  Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
  If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
  
  Import trace for requested module:
  ./node_modules/knex/lib/migrations/seed/Seeder.js
  ./node_modules/knex/lib/knex-builder/make-knex.js
  ./node_modules/knex/lib/knex-builder/Knex.js
  ./node_modules/knex/lib/index.js
  ./node_modules/knex/knex.js
  ./src/database/connection.js
  ./src/pages/index.js
  
  https://nextjs.org/docs/messages/module-not-found
  Could not find files for / in .next/build-manifest.json
  Could not find files for / in .next/build-manifest.json
  </code></pre>
  <p>Is it possible to integrate Knex.js to Next.js and if it's not, then what are the alternatives?</p>