Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda