给定一个 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 无法识别export
ES 模块中的语句。
是否有任何选项可以将 ES 模块导入 UI5 控制器?
使用版本:OpenUI5 1.96.0