如何在 UI5 中检测循环依赖模块?

问题描述 投票:0回答:1

鉴于:

sap.ui.define([ // in my/ModuleA.js
  // "...",
  "./ModuleB",
], function (/*...,*/ModuleB) {
  // ...             ModuleB is undefined here
  return/*...*/;
});
sap.ui.define([ // in my/ModuleB.js
  // "...",
  "./ModuleA"
], function (/*...,*/ModuleA) {
  // ...             ModuleA is undefined here
  return/*...*/;
});

构建并运行应用程序后,检查生成的

Component-preload.js
显示
ModuleB
中的
my/ModuleA.js
参数或
ModuleA
中的
my/ModuleB.js
参数为
undefined

在小项目中很容易检测到这种循环依赖关系。但是如果有多个模块并且它们的依赖关系很复杂,我如何轻松地检测到此类缺陷呢?

sapui5 amd
1个回答
2
投票
  1. 打开浏览器控制台并确保启用查看所有“详细”日志。

  2. 使用以下 UI5 配置 URL 参数运行应用程序

    • sap-ui-xx-debugModuleLoading
       值为 
      true
    • sap-ui-logLevel
       值为 
      ALL
  3. 在日志中,按“检测到周期”进行过滤。

    在“my/ModuleB.js”和“my/ModuleA.js”之间检测到循环,为“my/ModuleA.js”返回

    undefined
    - sap.ui.ModuleSystem
    在“my/ModuleA.js”和“my/ModuleB.js”之间检测到循环,为“my/ModuleB.js”返回 undefined
     - sap.ui.ModuleSystem

    e7daa82

     (UI5 1.121) 起,会记录实际错误并显示以下消息:
    

    检测到依赖关系循环:[...] sap.ui.ModuleSystem。

在UI5库开发中

仅从 UI5

1.91

提交:
initLibrary
)起,才允许使用所需 
"sap/ui/core/Core" 模块中的 API d83868e
 初始化您的库。在较低的 UI5 版本中,如果由于循环依赖而在引导过程早期需要,
"sap/ui/core/Core"
 模块可能会解析为 
undefined

另请参阅

UI5 文档中的
  • 加载模块的最佳实践
  • 解决错误的相关问答
  • “使用匿名define()调用的模块必须通过require()调用加载”.
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.