Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
Can I use Knex.js with Next.js?

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:

import knex from 'knex';

const connection = knex({
  client: 'mysql',
  connection: process.env.DATABASE_URL,
  asyncStackTraces: true,
  debug: true
});

export default connection;

And whenever I try to use it in my index page, which looks like this:

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 (
    <>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <Navbar />
      <Container className="text-center">
        <Row>
          <Col>
            {test}
          </Col>
        </Row>
      </Container>
    </>
  )
}

I receive this error:

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

Is it possible to integrate Knex.js to Next.js and if it's not, then what are the alternatives?

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda