Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_REQUIRE_ESM #161

Closed
cybercoder opened this issue Aug 20, 2022 · 4 comments
Closed

ERR_REQUIRE_ESM #161

cybercoder opened this issue Aug 20, 2022 · 4 comments

Comments

@cybercoder
Copy link

Error [ERR_REQUIRE_ESM]: require() of ES Module ./node_modules/@keycloak/keycloak-admin-client/lib/index.js from ./node_modules/nestjs-keycloak-admin/dist/main/service.js not supported.
Instead change the require of index.js in ./node_modules/nestjs-keycloak-admin/dist/main/service.js to a dynamic import() which is available in all CommonJS modules.

platform: mac os
node version: v16.17.0
nestjs version: 9.0
nestjs-keycloak-admin version: 1.8.7
keycloak version: 19.0.1
keycloak docker image: quay.io/keycloak/keycloak:19.0.1

@anonrig
Copy link
Owner

anonrig commented Aug 20, 2022

Hey @cybercoder

This is related to @keycloak/keycloak-admin-client making the decision to distribute their code with only ESM support (without CJS).

Please look into the issues keycloak/keycloak-nodejs-admin-client#523, keycloak/keycloak-nodejs-admin-client#519 and keycloak/keycloak-nodejs-admin-client#487

@anonrig anonrig closed this as completed Aug 20, 2022
@cybercoder
Copy link
Author

cybercoder commented Aug 20, 2022

for a workaround I've added:

  "resolutions": {
    "@keycloak/keycloak-admin-client": "^18.0.2"
  },

to my package.json file and run yarn, Also added graphql package.
And it's working. But it hadn't solve my problem with:

WARN [KeycloakService] Missing token set on refreshGrant.

How ever, thanks for your attention.

It seems the refreshGrunt function is calling somewhere before initialize, So for another workaround I've added

    async refreshGrant() {
        if (!this.tokenSet) await this.initialize();
 ....

to service.js file
And comment await client.initialize(); in the module.js file.

@anonrig
Copy link
Owner

anonrig commented Aug 20, 2022

Can you open a pull request if this needs to be resolved on our side?

@anonrig
Copy link
Owner

anonrig commented Aug 29, 2022

I've added a part to README to tell developers about the decision of ESM, and released a new version to stop distributing CJS on 2.0.0 (https://github.com/anonrig/nestjs-keycloak-admin/releases/tag/v2.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants