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

177
Views
Using imports conditionally without import()

This may sound weird but I need to use imports in a conditional way and without using await import() .

Here's a quick example, lets say I have this code:

import { en } from './langs/en.json';
import { fr } from './langs/fr.json';  

And I want to conditionally use en or fr.
Something like:

const selectedLang = "en";
const lang = global[selectedLang]; 

Is there a way of doing so?
I know that under the browser all global variables are stored in the window object.
But it is not the case with this library.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could use plain old require for this:

const selectedLang = "en";
const lang = require(`./langs/${selectedLang}.json`);
about 4 years ago · Juan Pablo Isaza Report
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!