Fix Pseudo Modules

作者 UI52b8c4a944e39無授權條款收錄於 2026年10月8日更新於 2026年10月8日

Fix pseudo module and implicit global issues that UI5 linter reports but cannot auto-fix. Use this skill when linter outputs: - `no-pseudo-modules` with messages about deprecated enum or DataType pseudo module access - `no-implicit-globals` with messages about module not exported by library or OData globals Trigger on: direct enum imports (sap/ui/core/BarColor), direct DataType imports (sap/ui/core/CSSSize), library.EnumName access, odata.compare/fillUriTemplate/uriEncode in bindings. Provides guidance on proper module imports for enums, DataTypes, and OData expression addons.

AI 產生的概覽

指導修正 UI5 檢查器回報的偽模組與隱式全域錯誤,透過調整模組匯入方式解決。

功能
此技能說明如何處理 UI5 檢查器無法自動修正的問題:已棄用的列舉與 DataType 偽模組存取、透過函式庫匯出存取但函式庫並未匯出的模組,以及隱式 OData 全域符號。它將每條檢查規則與訊息模式對應到修正策略,並提供修改前後的程式碼:從函式庫模組匯入列舉與 DataType、直接匯入類別、為 odata.* 函式匯入 ODataExpressionAddons。內容也涵蓋 XML 檢視,需在其中加入 core:require 項目,並列出常見偽模組與其對應的函式庫模組。
適用情境
當 UI5 檢查器輸出 no-pseudo-modules(列舉或 DataType 偽模組存取)或 no-implicit-globals(模組未被函式庫匯出、OData 內建全域符號)時使用。適用於採用這些寫法的 JavaScript 控制器與 XML 檢視。
執行需求
未隨附任何指令碼或工具,僅為指引說明。前提是 UI5 檢查器已輸出相關規則結果,且專案使用 UI5 模組載入方式(sap.ui.define、XML 檢視)。

Fix Pseudo Modules and Implicit Globals

This skill fixes pseudo module access and implicit global issues that the UI5 linter detects but cannot auto-fix because they require understanding proper module import patterns.

Linter Rules Handled

Rule IDMessage PatternThis Skill's Action
no-pseudo-modulesDeprecated access of enum pseudo module '...'Import via library module
no-pseudo-modulesDeprecated access of DataType pseudo module '...'Import via library module
no-implicit-globalsAccess of module '...' not exported by library '...'Import module directly
no-implicit-globalsOData built-in global symbols must not be used implicitlyImport ODataExpressionAddons

When to Use

Apply this skill when you see linter output like:

MyController.js:5:5 error Deprecated access of enum pseudo module 'sap/ui/core/BarColor'  no-pseudo-modulesMyController.js:8:5 error Deprecated access of DataType pseudo module 'sap/ui/core/CSSSize'  no-pseudo-modulesMyController.js:15:5 error Access of module 'sap/ui/unified/DateRange' not exported by library 'sap/ui/unified/library'  no-implicit-globalsMyView.view.xml:20:5 error OData built-in global symbols must not be used implicitly  no-implicit-globals

Background: Pseudo Modules

In UI5, enums and DataTypes were historically accessed as if they were modules (e.g., sap/ui/core/BarColor). These are "pseudo modules" - they don't exist as real files but are resolved at runtime from the library module. In modern UI5, direct pseudo module imports are deprecated.

Fix Strategy

1. Enum Pseudo Module Access

Problem: Importing enums as direct modules.

javascript
// Before - triggers no-pseudo-modulessap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/ui/core/BarColor",           // Pseudo module!    "sap/m/ListSeparators"            // Pseudo module!], function(Controller, BarColor, ListSeparators) {    "use strict";
    return Controller.extend("my.app.controller.Main", {        onInit: function() {            var color = BarColor.Positive;            var separator = ListSeparators.All;        }    });});

Fix Strategy: Import from the library module and access the enum as a property.

javascript
// After - import from librarysap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/ui/core/library",           // Import library    "sap/m/library"                  // Import library], function(Controller, coreLibrary, mLibrary) {    "use strict";
    // Extract enums from library    var BarColor = coreLibrary.BarColor;    var ListSeparators = mLibrary.ListSeparators;
    return Controller.extend("my.app.controller.Main", {        onInit: function() {            var color = BarColor.Positive;            var separator = ListSeparators.All;        }    });});

Common Enum Pseudo Modules and Their Libraries:

Pseudo ModuleLibrary ModuleEnum Access
sap/ui/core/BarColorsap/ui/core/librarycoreLibrary.BarColor
sap/ui/core/ValueStatesap/ui/core/librarycoreLibrary.ValueState
sap/ui/core/TextDirectionsap/ui/core/librarycoreLibrary.TextDirection
sap/ui/core/TextAlignsap/ui/core/librarycoreLibrary.TextAlign
sap/ui/core/MessageTypesap/ui/core/librarycoreLibrary.MessageType
sap/m/ListSeparatorssap/m/librarymLibrary.ListSeparators
sap/m/ListModesap/m/librarymLibrary.ListMode
sap/m/ListTypesap/m/librarymLibrary.ListType
sap/m/ButtonTypesap/m/librarymLibrary.ButtonType
sap/m/InputTypesap/m/librarymLibrary.InputType

2. DataType Pseudo Module Access

Problem: Importing DataTypes as direct modules.

javascript
// Before - triggers no-pseudo-modulessap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/ui/core/CSSSize"            // DataType pseudo module!], function(Controller, CSSSize) {    "use strict";
    return Controller.extend("my.app.controller.Main", {        // Using CSSSize type    });});

Fix Strategy: Import from the library module.

javascript
// After - import from librarysap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/ui/core/library"], function(Controller, coreLibrary) {    "use strict";
    var CSSSize = coreLibrary.CSSSize;
    return Controller.extend("my.app.controller.Main", {        // Using CSSSize type    });});

Common DataType Pseudo Modules:

Pseudo ModuleLibrary Module
sap/ui/core/CSSSizesap/ui/core/library
sap/ui/core/CSSColorsap/ui/core/library
sap/ui/core/URIsap/ui/core/library
sap/ui/core/IDsap/ui/core/library
sap/ui/core/Percentagesap/ui/core/library

3. Implicit Globals via Library Access

Problem: Accessing modules via library exports that aren't actually exported.

javascript
// Before - triggers no-implicit-globalssap.ui.define([    "sap/ui/unified/library",    "sap/ui/core/library"], function(unifiedLibrary, coreLibrary) {    "use strict";
    // These modules are NOT exported by the library!    var DateRange = unifiedLibrary.DateRange;              // Error    var DOMAttribute = coreLibrary.tmpl.DOMAttribute;      // Error});

Fix Strategy: Import the module directly.

javascript
// After - import modules directlysap.ui.define([    "sap/ui/unified/DateRange",           // Direct import    "sap/ui/core/tmpl/DOMAttribute"       // Direct import], function(DateRange, DOMAttribute) {    "use strict";
    // Use directly});

Rule of Thumb:

  • Enums and DataTypes: Access via library module (e.g., library.EnumName)
  • Classes/Controls: Import directly (e.g., sap/ui/unified/DateRange)

4. OData Expression Addons

Problem: Using OData built-in functions in expression bindings without importing.

javascript
// Before - triggers no-implicit-globalssap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/m/Text"], function(Controller, Text) {    "use strict";
    return Controller.extend("my.app.controller.Main", {        onInit: function() {            var oText = new Text({                // Using odata.compare without import!                text: "{= odata.compare(${/value1}, ${/value2}) }"            });        }    });});

Fix Strategy: Import ODataExpressionAddons module.

javascript
// After - import ODataExpressionAddonssap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/m/Text",    "sap/ui/model/odata/ODataExpressionAddons"  // Required for odata.* functions], function(Controller, Text, ODataExpressionAddons) {    "use strict";
    return Controller.extend("my.app.controller.Main", {        onInit: function() {            var oText = new Text({                // Now works - ODataExpressionAddons is imported                text: "{= odata.compare(${/value1}, ${/value2}) }"            });        }    });});

OData Functions Requiring Import:

OData FunctionAlternative Direct Module
odata.comparesap/ui/model/odata/v4/ODataUtils
odata.fillUriTemplatesap/ui/thirdparty/URITemplate
odata.uriEncodesap/ui/model/odata/ODataUtils

Note: Importing sap/ui/model/odata/ODataExpressionAddons is the simplest solution as it registers all OData expression functions.

5. OData Functions in XML Views

Problem: Using OData functions in XML view bindings without import.

xml
<!-- Before - triggers no-implicit-globals --><mvc:View    xmlns:mvc="sap.ui.core.mvc"    xmlns="sap.m">    <Text text="{= odata.compare(${/price1}, ${/price2}) }" /></mvc:View>

Fix Strategy: Add core:require for ODataExpressionAddons.

xml
<!-- After - with core:require --><mvc:View    xmlns:mvc="sap.ui.core.mvc"    xmlns="sap.m"    xmlns:core="sap.ui.core"    core:require="{        ODataAddons: 'sap/ui/model/odata/ODataExpressionAddons'    }">    <Text text="{= odata.compare(${/price1}, ${/price2}) }" /></mvc:View>

Implementation Steps

  1. Identify the issue type from the linter message:

    • "enum pseudo module" → Import from library
    • "DataType pseudo module" → Import from library
    • "not exported by library" → Import module directly
    • "OData built-in global" → Import ODataExpressionAddons
  2. Determine the correct library for enums/DataTypes:

    • Check the module path prefix (e.g., sap/ui/core/ → sap/ui/core/library)
  3. Update imports:

    • Add library import for enums/DataTypes
    • Add direct module import for classes
    • Add ODataExpressionAddons for OData functions
  4. Update code references:

    • Extract enum/DataType from library: var EnumName = library.EnumName;
    • Use directly imported modules
  5. For XML views: Add core:require when needed

Example Fix Session

Given linter output:

MyController.js:3:5 error Deprecated access of enum pseudo module 'sap/ui/core/ValueState'  no-pseudo-modulesMyController.js:4:5 error Access of module 'sap/ui/unified/DateRange' not exported by library 'sap/ui/unified/library'  no-implicit-globalsMyController.js:25:5 error OData built-in global symbols must not be used implicitly  no-implicit-globals

Before:

javascript
sap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/ui/core/ValueState",    "sap/ui/unified/library"], function(Controller, ValueState, unifiedLibrary) {    "use strict";
    var DateRange = unifiedLibrary.DateRange;  // Error: not exported
    return Controller.extend("my.app.controller.Main", {        onInit: function() {            var state = ValueState.Error;
            var oDateRange = new DateRange({                startDate: new Date()            });        },
        formatComparison: function() {            return "{= odata.compare(${/val1}, ${/val2}) }";  // Error: no import        }    });});

After:

javascript
sap.ui.define([    "sap/ui/core/mvc/Controller",    "sap/ui/core/library",                          // For ValueState enum    "sap/ui/unified/DateRange",                     // Direct import    "sap/ui/model/odata/ODataExpressionAddons"      // For odata.* functions], function(Controller, coreLibrary, DateRange, ODataExpressionAddons) {    "use strict";
    var ValueState = coreLibrary.ValueState;  // Extract from library
    return Controller.extend("my.app.controller.Main", {        onInit: function() {            var state = ValueState.Error;
            var oDateRange = new DateRange({                startDate: new Date()            });        },
        formatComparison: function() {            return "{= odata.compare(${/val1}, ${/val2}) }";  // Now works        }    });});

Notes

  • Library modules only export enums and DataTypes, not classes/controls
  • Always import controls and classes directly by their full module path
  • The ODataExpressionAddons import is needed even though you don't use the variable directly - it registers the functions at load time
  • Pseudo module deprecation helps identify improper dependencies and improves load time optimization

Related Skills

  • fix-js-globals: For other JavaScript global access patterns (no-globals on JS files — e.g., sap.ui.getCore(), jQuery, sap.ui.controller()), use fix-js-globals
  • fix-control-renderer: If pseudo module errors appear in renderer code alongside renderer-specific issues, use fix-control-renderer for the renderer modernization

來源與署名

來源:UI5/plugins-coding-agents位於plugins/ui5-modernization/skills/fix-pseudo-modules提交2b8c4a9

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架