Reactjs React lazy import语句可以';t句柄表达式

Reactjs React lazy import语句可以';t句柄表达式,reactjs,reflection,Reactjs,Reflection,因此,以下动态加载效果良好: return React.lazy(() => import("./hotels/components/" + componentName)); 以下操作不起作用: const path = "./hotels/components/"; return React.lazy(() => import(path + componentName)); 现在我认为它可能与minifier有关,因为在它工作的情况下,“

因此,以下动态加载效果良好:

return React.lazy(() => import("./hotels/components/" + componentName));
以下操作不起作用:

const path = "./hotels/components/";
return React.lazy(() => import(path + componentName));
现在我认为它可能与minifier有关,因为在它工作的情况下,“import”在vscode中变成蓝色。如果不起作用,“导入”为黄色

此外,当我为不起作用的情况编译时,我得到以下警告:

Critical dependency: the request of a dependency is an expression
有人遇到过这个问题吗

我从这个类似的问题中尝试了一切:


后续操作解决了错误并消除了警告。只需嵌入变量

return React.lazy(() => import(`${path + componentName}`));

这回答了你的问题吗@Vietian Dinh它不起作用这可能对您有所帮助,请参阅。@Eric是的,这起作用了,谢谢