打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
如何分析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

, 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.

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

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 ).

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

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:

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:

Then I find the root cause here:

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

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.

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”.

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

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

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

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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
22 best GUI testing tools for developer
NativeScript – a Technical Overview
SAPUI5 project setup for beginners with HTML views – Part2: Navigation and storing data with a global model | SAP Blogs
SAP常用ok_code列表(ABAP Basis OK_Codes)
JavaScript数组中的九类方法
20个JS优化代码技巧
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服