Kwin_wayland 6.0.2 script. The workspace var is inderfined

Problem: the workspace global variable in main.js which was called from main.qml is underfined but if i use main.js as script entry point then all global kwin variables on place.
main.qml which run js script.

import QtQuick
import org.kde.plasma.plasma5support as PlasmaSupport
import org.kde.kwin
import org.kde.taskmanager as TaskManager
import "../code/main.js" as jsScript

Item {
    id: scriptRoot

    TaskManager.ActivityInfo {
        id: activityInfo

    PlasmaSupport.DataSource {
        id: mousePoller
        engine: 'executable'

    Loader {
        id: popupDialog
        source: "popup.qml"

        function show(text) {
            var area = workspace.clientArea(KWin.FullScreenArea, workspace.activeScreen, workspace.currentDesktop);
  , area, 1000);

    Component.onCompleted: {
        console.log("JS script: starting the script");
        (new jsScript.KWinDriver()).main();

I’ve found soulution in Polonium kwinscript. Move main.js to main.mjs. make an empty main.js with one useless print command because script do not install without main.js.

import "../code/main.mjs" as JsScript

    Component.onCompleted: {
        const api = {
            "workspace": Workspace,
            "options": Options,
            "kwin": KWin,

        console.log("Workspace------" + Workspace.currentDesktop)


function init(api) {
  const ctrl = new KWinDriver(api);
export { init };