I'm trying to render one component with react.lazy in the path is a variable on my props but i get error with the webpack.
My component father send the props like this:
<DynamicModal url = 'Impuesto/formulario' />
and the component with reactLazy is this one:
import React from 'react';
import { withRouter } from 'react-router';
import {SpinLoadingModal} from 'config/SpinLoading/index.js';
function DynamicModal(props) {
const path = props.url;
const LazyComponent = React.lazy(() => import(path));
return (
<React.Suspense fallback={<SpinLoadingModal />}>
<div>
<LazyComponent/>
</div>
</React.Suspense>
);
}
export default withRouter (DynamicModal);
And the error i can see in the console:
> Uncaught Error: Cannot find module 'Impuesto/formulario'
at DynamicModal lazy groupOptions: {} namespace object:5
(anonymous) @ DynamicModal lazy groupOptions: {} namespace object:5
>
> function webpackEmptyAsyncContext(req) {
// Here Promise.resolve().then() is used instead of new Promise() to prevent
// uncaught exception popping up in devtools
return Promise.resolve().then(function() {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
});
}
webpackEmptyAsyncContext.keys = function() { return []; };
webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
module.exports = webpackEmptyAsyncContext;
webpackEmptyAsyncContext.id = "./src/config/DynamicModal lazy recursive";
And this in my browser:
× Error: Cannot find module './Impuesto/formulario' (anonymous function) src/config lazy /^/.*$/ groupOptions: {} namespace object:123
I read before about check in console the import here in stack and trying to check with this code:
import(`../components/${res}`).then(() => {
console.log("Loaded")
}, (err)=>{
console.log("Error", err)
})
but dont help me too much and the error continue. Really thank you for any help or advice!
NOTE: if i change the code with:
const LazyComponent = React.lazy(() => import('Impuesto/formulario'));
this works but i really want to change with variable! Well if this is possible! lol