Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!