question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error [ERR_REQUIRE_ESM]

See original GitHub issue

Describe the bug

Hello 👋 Since I switched from "18.0.2" to "19.0.1", Typescript does not compile anymore

Version

19.0.1

Expected behavior

Typescript should compile without any error message.

Actual behavior

I have the following error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/anthonny/projects/aaa/node_modules/@keycloak/keycloak-admin-client/lib/index.js from /Users/anthonny/projects/aaa/packages/api/infra/server/keycloak-plugin.ts not supported.
Instead change the require of index.js in /Users/anthonny/projects/aaa/packages/api/infra/server/keycloak-plugin.ts to a dynamic import() which is available in all CommonJS modules.

How to Reproduce?

I have a Typescript project with this tsconfig.json:

{
  "extends": "@tsconfig/node16/tsconfig.json",
  "compilerOptions": {
    "outDir": "dist"
  }
}

Just import the lib and use the client

Anything else?

Everything is ok if I go back to "18.0.2", thank you for your support 🙏😘

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:9
  • Comments:26 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
anonrigcommented, Aug 20, 2022

The amount of pain the decision to convert the codebase is huge. Especially on packages that depend on this package.

There isn’t any logical reasoning behind converting a package to ESM only in terms of performance. Actually using ESM has worse performance than CJS in Node.js. (https://github.com/nodejs/node/issues/44186)

I recommend the distributors of this package change their decision and ease the pain of using this package.

The community is not ready for this kind of change.

6reactions
Nosfistiscommented, Aug 23, 2022

I applaud the move forward, yet this is a breaking change not mentioned anywhere clearly, and blocks development with mayor frameworks such as NestJS.

@GerDner I just booststrapped a new NestJS project and this works fine for me using the latest version of the Admin Client.

Could you upload it to a demo repo? I have done the same using the latest NestJS CLI and cannot create the Admin Client without triggering the error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The error [ERR_REQUIRE_ESM]: require() of ES Module not supported. Instead change the require of index.js to a dynamic import() which is available in...
Read more >
Error [ERR_REQUIRE_ESM]: How to use es6 modules in ...
You have to add this line of code in your package.json file "type" : "module" You will be able to use imports statements...
Read more >
ERR_REQUIRE_ESM - DEV Community ‍ ‍
Once you update you package deps you may face with the error mentioned in this note title: Error [ERR_REQUIRE_ESM]: Must use import to...
Read more >
Error ERR REQUIRE ESM | Must use import to load ES Module
Error ERR REQUIRE ESM | Must use import to load ES Module. 15K views 1 year ago JS - JavaScript · Sagar S....
Read more >
Error [ERR_REQUIRE_ESM]: Must use import to load ES ...
js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /my-project/node_modules/file- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found