严重依赖关系 - 依赖关系的请求是表达式Webpack [英] Critical dependencies - the request of a dependency is an expression Webpack

查看:1060
本文介绍了严重依赖关系 - 依赖关系的请求是表达式Webpack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的角度 c应用程序中的服务来创建 uibModal 如下

I am using a service in my angular application to create uibModal as follows

function modal(modalConfig){
                  var modalInstance = $uibModal.open({
                  animation: true,
                  template: require("../a/b/xyz.html"),
                  controller: modalConfig.controller,
                  size: modalConfig.size,
                  controllerAs: modalConfig.controllerAs,
                  bindToController : true,
                  resolve: modalConfig.resolveObj

                });
            }

请注意线路

 template: require("../a/b/xyz.html"),

我想在这样的位置使用一个变量

I want to use a variable in its place like this

 template: require(modalConfig.templateUrl),

但是当我使用变量代替硬编码值 webpack 给我

but when i use a variable in place of hard coded value webpack gives me

Critical dependencies:
83:22-54 the request of a dependency is an expression

我无法解决此错误。可能的原因是什么?

I am not able to resolve this error. What can be the possible reason for it?

我已经使用 node-express 服务器连续 webpack builds。我也看过其他答案,但他们没有解决我的查询。

I have used node-express server for continuous webpack builds. I have looked at other answers too but they didn't solve my query.

推荐答案

经过多次打击和试用找到解决方案。我做的是这样的:

After much hit and trial found the solution.What i did is this:

template: require("../../scripts" + modalConfig.templateUrl + ".html")

假设


  1. 所有文件所在的根文件夹是脚本

  2. ,该文件夹中的文件夹的相对路径该功能的写法是说 ../../脚本

  3. ../ .. / scripts + modalConfig.templateUrl + 。html将形成正确的路径要使用的文件。

  1. root folder under which all the file comes is scripts
  2. and the relative path of this folder from the file in which the function is written is say ../../scripts.
  3. ../../scripts + modalConfig.templateUrl + ".html" will form the correct path for the file to be used.

强制性说明


    总是写一些根文件夹的硬编码路径。不要把它放在变量中。所以这不会工作
  1. Always write some hardcoded path of root folder. Don't put it in variable. so this won't work

var context =../../scripts;
template:require(context + modalConfig.templateUrl +.html)

基本路径(如实际路径的一部分)必须进行硬编码,以便进行基本参考,因为它可以帮助webpack创建动态需求可能需要的所有模块的列表。

The base path (as in a part of the actual path) has to be hardcoded for basic reference, as in it helps webpack to create a list of all the modules which might be needed for the dynamic requires.

原因(来自webpack docs ),请阅读动态要求上下文模块

Reason (from webpack docs) , read dynamic requires and context module.

这篇关于严重依赖关系 - 依赖关系的请求是表达式Webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆