以笔者本套教材为例,每一步骤的源代码都托管在本人 Github 仓库里,每次上传之前,都确保本地测试通过。
但笔者编写过程中发现,之前测试通过的代码,可能几个月之后再执行,就会遇到白屏现象,即应用无法正常加载,或者无法在调试模式下正常加载。
举个具体的例子。本文写作于 2022年11月20日,进入步骤 6,运行命令行 ui5 serve
:
使用这个 url
,可以正常打开 SAP UI5 应用:
使用快捷键 Ctrl+Shift+Alt+P
切换到调试模式,然后根据如下 url,居然无法打开应用了:
http://localhost:8080/webapp/index.html?sap-ui-debug=true
错误消息:
ui5loader-dbg.js:1283 Access to XMLHttpRequest at ‘https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck-dbg.js’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
loadSyncXHR @ ui5loader-dbg.js:1283
requireModule @ ui5loader-dbg.js:1538
requireAll @ ui5loader-dbg.js:1730
executeModuleDefinition @ ui5loader-dbg.js:1796
ui5Define @ ui5loader-dbg.js:1929
eval @ Core-dbg.js?eval:8
execModule @ ui5loader-dbg.js:1645
requireModule @ ui5loader-dbg.js:1546
requireSync @ ui5loader-dbg.js:2056
(anonymous) @ sap-ui-core-dbg.js?bundle-code-0:1
ui5loader-dbg.js:1283 GET https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck-dbg.js net::ERR_FAILED 404
loadSyncXHR @ ui5loader-dbg.js:1283
requireModule @ ui5loader-dbg.js:1538
requireAll @ ui5loader-dbg.js:1730
executeModuleDefinition @ ui5loader-dbg.js:1796
ui5Define @ ui5loader-dbg.js:1929
eval @ Core-dbg.js?eval:8
execModule @ ui5loader-dbg.js:1645
requireModule @ ui5loader-dbg.js:1546
requireSync @ ui5loader-dbg.js:2056
(anonymous) @ sap-ui-core-dbg.js?bundle-code-0:1
ui5loader-dbg.js:1283 Access to XMLHttpRequest at ‘https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck.js’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
loadSyncXHR @ ui5loader-dbg.js:1283
requireModule @ ui5loader-dbg.js:1538
requireAll @ ui5loader-dbg.js:1730
executeModuleDefinition @ ui5loader-dbg.js:1796
ui5Define @ ui5loader-dbg.js:1929
eval @ Core-dbg.js?eval:8
execModule @ ui5loader-dbg.js:1645
requireModule @ ui5loader-dbg.js:1546
requireSync @ ui5loader-dbg.js:2056
(anonymous) @ sap-ui-core-dbg.js?bundle-code-0:1
ui5loader-dbg.js:1283 GET https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck.js net::ERR_FAILED 404
loadSyncXHR @ ui5loader-dbg.js:1283
requireModule @ ui5loader-dbg.js:1538
requireAll @ ui5loader-dbg.js:1730
executeModuleDefinition @ ui5loader-dbg.js:1796
ui5Define @ ui5loader-dbg.js:1929
eval @ Core-dbg.js?eval:8
execModule @ ui5loader-dbg.js:1645
requireModule @ ui5loader-dbg.js:1546
requireSync @ ui5loader-dbg.js:2056
(anonymous) @ sap-ui-core-dbg.js?bundle-code-0:1
ui5loader-dbg.js:1042 Uncaught ModuleError: Failed to resolve dependencies of ‘sap/ui/core/Core.js’
-> ‘sap/ui/core/ThemeCheck.js’: failed to load ‘sap/ui/core/ThemeCheck.js’ from https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck.js: Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ‘https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck.js’.
at makeModuleError (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1044:15)
at Module.failWith (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:816:13)
at https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1860:32
at requireAll (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1745:5)
at executeModuleDefinition (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1798:3)
at Object.ui5Define [as define] (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1931:3)
at eval (https://sapui5.hana.ondemand.com/resources/sap/ui/core/Core-dbg.js?eval:8:8)
at eval ()
at execModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1647:15)
at requireModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1548:5)
Caused by: ModuleError: failed to load ‘sap/ui/core/ThemeCheck.js’ from https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck.js: Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ‘https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck.js’.
at makeModuleError (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1044:15)
at Module.failWith (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:816:13)
at requireModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1545:13)
at requireAll (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1732:20)
at executeModuleDefinition (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1798:3)
at Object.ui5Define [as define] (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1931:3)
at eval (https://sapui5.hana.ondemand.com/resources/sap/ui/core/Core-dbg.js?eval:8:8)
at eval ()
at execModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1647:15)
at requireModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1548:5)
Caused by: Error: Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ‘https://sapui5.hana.ondemand.com/resources/sap/ui/core/ThemeCheck.js’.
at loadSyncXHR (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1285:8)
at requireModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1540:5)
at requireAll (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1732:20)
at executeModuleDefinition (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1798:3)
at Object.ui5Define [as define] (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1931:3)
at eval (https://sapui5.hana.ondemand.com/resources/sap/ui/core/Core-dbg.js?eval:8:8)
at eval ()
at execModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1647:15)
at requireModule (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:1548:5)
at Object.requireSync (https://sapui5.hana.ondemand.com/resources/sap-ui-core-dbg.js:2058:23)
本文余下部分,介绍如何分析这种怪问题。