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

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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