繁体   English   中英

关键依赖:依赖的请求是使用延迟加载时的表达式

[英]Critical dependency: the request of a dependency is an expression while using lazy loading

我正在尝试动态导入模块但出现以下错误 -

编译有问题:X

警告在./src/.../useCustomModule.js 21:21-56

关键依赖:依赖的请求是一个表达式

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);
};

注意:在 eslintrc.json 我有以下设置 - “ecmaVersion”:12,

最近,我也遇到了类似的问题,但是当我使用字符串插值时,警告消失了。 在您的代码中,尝试一下:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM