如何分析SAP UI5应用的undefined is not a function错误

简介: Recently I meet with an annoying Javascript error “undefined is not a function” during my Fiori development. After debugging the framework code for several hours

Recently I meet with an annoying Javascript error “undefined is not a function” during my Fiori development. After debugging the framework code for several hours


image.png


, I finally find a more efficient way to find the exact source code which causes the trouble. I would like to share this small tip with you and hope it could help.


Issue: When I am doing test on my application on a local tomcat, I could only see an empty screen.


For sure there must be some Javascript error occurred.


image.png


Open Chrome console and I see one Uncaught TypeError: undefined is not a function as expected.


image.png


Unfortunately this error is raised in UI5 framework js “UIComponent.js”, after I click the hyperlink in the screenshot above, I am automatically navigated to this file, however I do completely not understand what has happened here, in function ( q, C, U, V ).


image.png


Then I press Ctrl+Alt+Shift+P to switch on debug by marking checkbox “Use Debug Sources”.


image.png


Refresh UI and now the debug resource, UIComponent-dbg.js is loaded instead. Since what I bad need is the context of this error, or callstack, so I set a breakpoint on catch statement, line 47. Relaunch application UI and breakpoint is triggered.

I add variable e in Watch Expression:


image.png


Expand variable e in Watch Expressions and put the mouse to stack. The complete callstack is instantly displayed.

The topmost callstack shows the error occurs in line 154, column 36 of file ConnectionManager-dbg.js:


image.png


Then I find the root cause here:


image.png


the variable service.serviceUrl is not a String but an object of URI which does not have a method named “indexOf”:


image.png


Conclusion

Although this error is raised in UI framework js file, it is however an absolute application issue: the url of OData is defined in Configuration.js file by application as metadata, and UI framework in the runtime will ask for it by calling some callback functions defined by application and then consume it. Framework will assume always a String for OData service url returned by application.

After the following fix is done on application, the issue is fixed.


image.png


Any other alternative solution?

Later on I find another approach to find the position ( line 154, column 36 ) even without debugging.


I test my app with Firefox. To my surprise, it could directly display more detail about this error compared with Chrome: “j.serviceUrl.indexOf is not a function”.


image.png


The Firefox console shows this error occurs in sap-ui-core.js line 80


image.png


However I could not find any hit by searching “indexOf” within this file.


image.png


So I just again switch to Chrome and search serviceUrl.indexOf in Chrome instead, this time I get directly what I am looking for.


image.png


From this cause it seems that these two complementary powerful tool, Chrome and Firefox, could make our life as UI5 developer more easier.


相关文章
|
1月前
|
搜索推荐
SAP UI5 SmartTable.prototype._onMetadataInitialised 方法的深入介绍
SAP UI5 SmartTable.prototype._onMetadataInitialised 方法的深入介绍
32 0
|
3月前
|
数据库
130. SAP ABAP 更新函数(Update Function Module)执行出错的原因分析
130. SAP ABAP 更新函数(Update Function Module)执行出错的原因分析
25 0
|
3月前
|
数据库
SAP ABAP 更新函数(Update Function Module)执行出错的原因分析试读版
SAP ABAP 更新函数(Update Function Module)执行出错的原因分析试读版
35 0
|
6月前
|
缓存 开发工具 开发者
Fiori Elements 应用url 里参数 sap-ui-xx-viewCache=false 的作用
Fiori Elements 应用url 里参数 sap-ui-xx-viewCache=false 的作用
40 0
|
6月前
|
数据库
SAP ABAP Function Module 的动态调用方式使用方式介绍试读版
SAP ABAP Function Module 的动态调用方式使用方式介绍试读版
38 0
SAP ABAP Function Module 的动态调用方式使用方式介绍试读版
|
10月前
|
JavaScript
ElementUI this.$message is not a function 解决方法
ElementUI this.$message is not a function 解决方法
104 0
|
JavaScript 前端开发 Shell
在child_process域和错误的冒泡和捕获实践【Note.js】
在child_process域和错误的冒泡和捕获实践【Note.js】
|
JavaScript 开发者
组件-为什么组件的 data 必须是一个 function|学习笔记
快速学习组件-为什么组件的 data 必须是一个 function
82 0
|
Web App开发 JavaScript 前端开发
从规范去看Function.prototype.call到底是怎么工作的?
从规范去看Function.prototype.call到底是怎么工作的?
从规范去看Function.prototype.call到底是怎么工作的?