I’m trying to use the Keycloak Admin Client library in my Nodejs application.
Here is a snippet from my code:
import [... whatever ...]
import KcAdminClient from '@keycloak/keycloak-admin-client';
import { Credentials } from '@keycloak/keycloak-admin-client/lib/utils/auth';
export class Controller {
private kcAdminClient = new KcAdminClient();
[...]
However as soon as I run my application, I get the following error:
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/@keycloak/keycloak-admin-client/lib/index.js from .../server/logic/auth/users.ts not supported.
Instead change the require of index.js in .../server/logic/auth/users.ts to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (.../server/logic/auth/users.ts:10:49)
at m._compile (.../node_modules/ts-node/dist/index.js:791:29)
at require.extensions.<computed> [as .ts] (.../node_modules/ts-node/dist/index.js:793:16) {
code: 'ERR_REQUIRE_ESM'
}
But my code does not use require(), or, at least, I can’t find any “require” string in that source file.
What am I doing wrong?