【发布时间】:2021-10-14 18:40:22
【问题描述】:
给定一个 ES 模块 dictionaryAPI.mjs:
export const DICTIONARY_API = Object.freeze({
someKey: "someValue"
});
我想将它导入我的 UI5 控制器。据我了解,UI5 不支持.mjs 扩展,因此我将扩展从.mjs 更改为.js。然后,我尝试将其添加到 UI5 控制器中,确切地说,是实用程序控制器ControllerUtilities.js:
sap.ui.define([
"com/myApp/dictionaryAPI"
],
(dictionaryAPI) => ({…}));
当我运行应用程序时,出现错误:
'com/myApp/controller/ControllerUtilities.js': Unexpected token 'export'
sap-ui-core.js:53 Uncaught (in promise) ModuleError: Failed to resolve dependencies of 'com/myApp/controller/Login.controller.js'
-> 'com/myApp/controller/BaseController.js'
-> 'com/myApp/controller/ControllerUtilities.js': Unexpected token 'export'
at p1 (https://openui5nightly.hana.ondemand.com/resources/sap-ui-core.js:53:213)
at j1.failWith (https://openui5nightly.hana.ondemand.com/resources/sap-ui-core.js:40:43)
at https://openui5nightly.hana.ondemand.com/resources/sap-ui-core.js:65:1556
Caused by: SyntaxError: Unexpected token 'export'
看起来,UI5 无法识别 ES 模块中的 export 语句。
是否有任何选项可以将 ES Module 导入 UI5 控制器?
使用版本:OpenUI5 1.96.0
【问题讨论】:
-
不仅如此,您还可以考虑使用官方的 UI5 typescript 支持,它允许导入和导出语句github.com/SAP/ui5-typescript
标签: javascript sapui5 ui5-tooling