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

469
Vistas
WebPack - dynamic import workaround or solution

We have a component hosted on the cloud (like npm) and we want it to be able to do dynamic imports.

The above component, gets a prop with a path where possible components will be located. Then on load, it will try to import some components from the given path.

lets say thats our import code:

function loadDynamicComponent(componentsPath) {
    let Component;

    try {
        Component = React.lazy(() =>
            import(`${componentsPath}/${component}`)
        );
    } catch {
        Component = () => <div>No Component found by the name: {component}</div>;
    }

    return Component;
}

Now as we understand, Webpack must receive at least one relative level within the import path before it can use dynamic path variable.

something like that will work:

Component = React.lazy(() =>
   import(`../components/${componentsPath}/${component}`)
);

But as we use a component that itself is imported from outer source and not our project folders, we need the path to be fully dynamic like that:

Component = React.lazy(() =>
   import(`${componentsPath}/${component}`)
);

Does anyone has an idea of how something like that can be achieved?

BTW, we use Creat-React-App as a boilerplate, but if ejecting will help solving the problem we are happy to hear about it too :)

Thanks a lot in advance!!!!

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