【问题标题】:React lazy import statement can't handle expressionReact惰性导入语句无法处理表达式
【发布时间】:2021-01-01 12:48:10
【问题描述】:

所以下面的动态加载工作正常:

return React.lazy(() => import("./hotels/components/" + componentName));

以下不起作用:

const path = "./hotels/components/";
return React.lazy(() => import(path + componentName));

现在我认为它可能与缩小器有关,因为在它工作的情况下,“导入”在 vscode 中变为蓝色。如果它不起作用,“导入”是黄色的。

此外,当我针对它不起作用的情况进行编译时,我会收到以下警告:

Critical dependency: the request of a dependency is an expression

有人遇到过这个问题吗?

我尝试了这个类似问题的所有内容:

Webpack - Critical dependency: the request of a dependency is an expression

【问题讨论】:

标签: reactjs reflection


【解决方案1】:

以下解决了错误并消除了警告。只需要嵌入变量。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多