[英]Critical dependency: the request of a dependency is an expression while using lazy loading
I am trying to dynamically import modules but getting following error -我正在尝试动态导入模块但出现以下错误 -
Compiled with problems:X编译有问题:X
WARNING in./src/.../useCustomModule.js 21:21-56警告在./src/.../useCustomModule.js 21:21-56
Critical dependency: the request of a dependency is an expression关键依赖:依赖的请求是一个表达式
import React from "react";
import PropTypes from "prop-types";
export const moduleMapping = {
CONTEXT_ONE: "./....contextOnePath",
CONTEXT_TWO: "./....contextTwoPath",
};
const getModule = (moduleName) => {
const module = React.lazy(() => import(moduleMapping[moduleName]));
return module;
};
export const useCustomModule = (moduleName) => {
return getModule(moduleName);
};
Note: In eslintrc.json I have following settings - "ecmaVersion": 12,注意:在 eslintrc.json 我有以下设置 - “ecmaVersion”:12,
Recently, I also faced a similar issue but when I used string interpolation, the warning went away.最近,我也遇到了类似的问题,但是当我使用字符串插值时,警告消失了。 In your code, give a try to this:
在您的代码中,尝试一下:
const getModule = (moduleName) => {
const module = React.lazy(() => import(`${moduleMapping[moduleName])}`);
return module;
};
const getModule = (moduleName) => {
const module = React.lazy(() => import(`${moduleMapping[moduleName])}`);
return module;
}; };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.