Error [ERR_REQUIRE_ESM]
See original GitHub issueDescribe 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:
- Created a year ago
- Reactions:9
- Comments:26 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
I applaud the move forward, yet this is a breaking change not mentioned anywhere clearly, and blocks development with mayor frameworks such as NestJS.
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.