Corredor server script requires dynamic import

Hi,

I need to integrate keycloak admin client (@keycloak/keycloak-admin-client) into corredor server script but i have problems import it to corredor server scripts. The problems showed in corredor docker image logs is as follows:

=======
Instead change the require of index.js in /cvti/scripts/cvti/server-scripts/cvti/CVTIExecFromAPIGW.js to a dynamic import() which is available in all CommonJS modules.
at require.extensions. [as .js] (/corredor/node_modules/ts-node/dist/index.js:552:20)
at Object. (/cvti/scripts/cvti/server-scripts/cvti/CVTIExecFromAPIGW.js:7:49)
at m._compile (/corredor/node_modules/ts-node/dist/index.js:556:29)
at require.extensions. [as .js] (/corredor/node_modules/ts-node/dist/index.js:558:16)
at ServerScripts.require (/corredor/src/services/server-scripts.ts:147:20)
at /corredor/src/services/server-scripts.ts:122:72
src: “/cvti/scripts/cvti/server-scripts/cvti/CVTIExecFromAPIGW.js”
[1730884281483] WARN (services.server-scripts): could not require() script: Error [ERR_REQUIRE_ESM]: require() of ES Module /cvti/scripts/cvti/node_modules/@keycloak/keycloak-admin-client/lib/index.js from /cvti/scripts/cvti/server-scripts/cvti/FailedScript.js not supported.
Instead change the require of index.js in /cvti/scripts/cvti/server-scripts/cvti/FailedScript.js to a dynamic import() which is available in all CommonJS modules.
at require.extensions. [as .js] (/corredor/node_modules/ts-node/dist/index.js:552:20)
at Object. (/cvti/scripts/cvti/server-scripts/cvti/FailedScript.js:7:49)
at m._compile (/corredor/node_modules/ts-node/dist/index.js:556:29)
at require.extensions. [as .js] (/corredor/node_modules/ts-node/dist/index.js:558:16)
at ServerScripts.require (/corredor/src/services/server-scripts.ts:147:20)
at /corredor/src/services/server-scripts.ts:122:72
src: “/cvti/scripts/cvti/server-scripts/cvti/FailedScript.js”

=======

i am using corredor docker image 2023.9.8

Server script and package.json attached. I have check usage of axios, it working correctly. Also try to import dynamically as noticed in stacktrace but without success.

Any suggestion ?

Regards, Miro.

==== test scripts: ====

import { loadCreds } from ‘…/…/lib//util.js’
import {userinfo} from ‘…/…/lib’
import axios from ‘axios’

/*

*/

import KcAdminClient from ‘@keycloak/keycloak-admin-client’;

export const testaxios = async (uuid) => {
const ret = await axios.get(“http://www.google.com”);
console.log(ret);

}

// comment out thos function to make script do not have problems with import
export const userinfo = async (uuid) => {
console.log(“userinfo::#0::”+JSON.stringify(uuid));
console.log(“userinfo::#1::”+JSON.stringify(uuid));
console.log(“INSPECT::”+KcAdminClient+ " :: " + JSON.stringify(KcAdminClient));
console.log(“INSPECT::”+KcAdminClient+ " :: " + typeof(KcAdminClient));
try {
const kcAdminClient = new KcAdminClient(
{
baseUrl: ‘https://sso.someweher.xx’,
realmName: ‘master’,
requestOptions: {
},
}
);

            console.log("INSPECT::K::"+kcAdminClient+ " :: " +typeof(kcAdminClient)+" :: "+ JSON.stringify(kcAdminClient));

             await kcAdminClient.auth({
               username: 'admin',
               password: 'admin',
               grantType: 'password',
               clientId: 'admin-cli',
             });
            const users = await kcAdminClient.users.find({ q: "uuid:"+uuid });
            return users[0];
    } catch (e){
            console.log("EXCEPTION::"+e+ " :: " + JSON.stringify(e));
    }
    return null;

};

export default {
label: ‘CVTI Console Log’,
description: ‘CVTI Console Log’,

  • triggers ({ on }) {
    yield on(‘manual’)
    .for(‘system’)
    },

async exec (args, { logger, ctx }) {

     const u  = await testaxios('');

// const u = await userinfo(‘’);

}
}

==== package.json

{
“name”: “cvti”,
“version”: “2020.12.0”,
“description”: “CVTI Extensions”,
“main”: “lib/index.js”,
“license”: “Apache-2.0”,
“scripts”: {
“start”: “node -r esm lib/index.js”
},
“dependencies”: {
@cortezaproject/corteza-ext-renderer”: “^2020.12.0”,
@keycloak/keycloak-admin-client”: “^26.0.5”,
“axios”: “^0.21.1”,
“base-64”: “^0.1.0”,
“docusign-esign”: “^5.3.0”,
“esm”: “^3.2.25”,
“form-data”: “^3.0.0”,
“keycloak-js”: “^26.0.5”,
“pdf-to-base64”: “^1.0.2”,
“ts-node”: “^10.9.2”
}
}