简体   繁体   English

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

[英]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.

相关问题 关键依赖:依赖的请求是一个表达式 webpack svelte - Critical dependency: the request of a dependency is an expression webpack svelte 关键依赖:一个依赖的请求是一个表达式——react-universal-component - Critical dependency: the request of a dependency is an expression -- react-universal-component 关键依赖项:依赖项的请求是jQuery Form Validator插件上的一个表达式 - Critical dependency: the request of a dependency is an expression on jQuery Form Validator plugin Webpack编译不正确(严重依赖性:依赖性的请求是一个表达式) - Webpack not properly compiling (Critical dependency: the request of a dependency is an expression) 关键依赖:依赖的请求是一个表达式(Angular CLI 警告) - Critical dependency: the request of a dependency is an expression (Angular CLI Warning) 延迟加载和依赖项解析 - Lazy loading and dependency resolution 如何解决我的npm包的“关键依赖关系:依赖关系的请求是一个表达式”错误? - How to resolve “Critical dependency: the request of a dependency is an expression” error for my npm package? ./node_modules/express/lib/view.js 中的 Webpack 警告关键依赖:依赖的请求是一个表达式 - Webpack WARNING in ./node_modules/express/lib/view.js Critical dependency: the request of a dependency is an expression 警告-动态加载csv时严重依赖 - Warning - Critical Dependency when dynamically loading csv 使用 react-pdf 时出现严重依赖警告 - Critical dependency warning when using react-pdf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM