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

215
Visualizações
Base path for `require()`

Note! I went through many answers before asking the question but did not find the answer I want. Please, do not mark it as a duplicate.

In es modules we can set baseUrl in jsconfig.json:

{
  "compilerOptions": {
    "baseUrl": "/base"
  }
}
or
{
  "compilerOptions": {
    "baseUrl": "."
  }
}

Then we can import any files from that base directory throughout the project:

import Grand from 'base/child/grands'

I want to achieve the same thing in commonjs syntax (which uses require() ). I want to be able to import files(modules) like this:

const Grand = require('base/child/grands')

not this way:

const Grand = require('./base/child/grands')

How can I achieve this?

P.S. I am working on a Next.js project which uses 'es modules' for frontend and 'commonjs' for backend.

about 4 years ago · Juan Pablo Isaza
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