dynamic require in production
lauterry opened this issue · comments
LAU Thierry commented
Hello
My application is server side rendered.
Here is my asyncComponent which load a HomeBackground depending on a marketing code :
export default asyncComponent({
resolve: () => new Promise(resolve => {
require.ensure([], () => {
const path = getStore().getState().marketing.code || "default";
const component = require("./" + path + "/HomeBackground.jsx");
resolve(component);
}, "home-background-loader");
}),
serverMode: "resolve"
});
In dev mode, everything works perfectly.
However when I build the app for production, I encounter the following issue (marketing code here is "ul") :
I wonder if dynamic require is handled by react-async-component ?
What am I doing wrong ?
Best regards
Michael Frohberg commented
Just a shot in the dark but to the best of my knowledge jsx won't compile in the browser. Perhaps use the webpack resolve property to allow you to import that file without specifying the extension.